は、私が想定し、すでに製品タイプセレクタにギフトカードを追加しました。しかし、ここでは完全性のために2番目の関数で同じ名前を使用しています。
add_filter('product_type_selector', 'so_42835590_add_product_type');
function so_42835590_add_product_type($types){
// Key should be exactly the same as in the class product_type parameter
$types[ 'gift-card' ] = __('Gift Card', 'your-plugin');
return $types;
}
あなたはwoocommerce_product_data_tabs
をフィルタリングすることにより、独自のカスタムタブを追加することができますが、あなたはまた、既存のタブにクラスを追加することができます。クラスは、代謝産物javascriptが何を表示するかを決定するために使用するもので、製品タイプが変更されたときに非表示にするものです。
add_filter('woocommerce_product_data_tabs', 'so_42835590_product_data_tabs');
function so_42835590_product_data_tabs($tabs) {
// Add an additional class to an existing tab, ex: Variations.
$tabs[ 'variations' ][ 'class' ][] = 'show_if_gift-card'; // gift-card must match key from above
return $tabs;
}
編集あなたは、既存の属性の「ばらつきを有効」タブの表示を制御するために、いくつかのJavaScriptを追加する必要がない、と属性が追加されたとき。これはトリックを行う必要があります:
jQuery(function ($) {
// Variable type options are valid for variable workshop.
$('.show_if_variable:not(.hide_if_gift-card)').addClass('show_if_gift-card');
// Trigger change
$('select#product-type').change();
// Show variable type options when new attribute is added.
$(document.body).on('woocommerce_added_attribute', function(e) {
$('#product_attributes .show_if_variable:not(.hide_if_gift-card)').addClass('show_if_gift-card');
var $attributes = $('#product_attributes').find('.woocommerce_attribute');
if ('gift-card' == $('select#product-type').val()) {
$attributes.find('.enable_variation').show();
}
});
});
ありがとう@helgathevikingそれは動作します。あなたはいくつかの詳細を追加してください、どのように属性タブに "バリエーションのための"チェックボックスフィールドを表示するには? http://prntscr.com/el16t1これは、製品タイプが可変製品の場合のみ表示されます。 –
私が追加したスクリプトを見てください。 – helgatheviking
ありがとう@helgatheviking –