나는 가정 당신은 이미 제품 유형 선택에 기프트 카드를 추가했습니다. 그러나 두 번째 기능에서 동일한 이름을 사용하기 때문에 완전성을 위해 여기에 추가 할 것입니다.
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
를 필터링하여 사용자 지정 탭을 추가 할 수 있지만, 당신은 또한 기존 탭 클래스를 추가 할 수 있습니다. 클래스는 metabox 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;
}
편집은 기존의 속성에서 탭 "변화를 가능"및 속성이 추가 될 때. 이 트릭을해야합니다 :
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 –