2017-03-16 4 views
2
  • 기본적으로 상품 유형 "기프트 카드"를 추가하는 "기프트 카드"용 플러그인을 설치했습니다.
    • 그 기능을 향상시켜야합니다.
    • 다른 탭도 있지만 '유사 콘텐츠'탭은 이 아닙니다.
    • 내 맞춤 제품 유형이 일 수 있도록이 탭을 어떻게 추가 할 수 있습니까?
    • 스크린 샷 : http://prntscr.com/ekogwd
    • 그리고 내 맞춤 제품 유형을 사용해야한다는 것은 엄격한 의미에서 변수 제품 유형으로 변경할 수 없음을 의미합니다.
    • woocommerce를 사용하여 내 맞춤 제품 유형 "기프트 카드"에이 탭을 수동으로 추가 할 수있는 후크, 액션 또는 필터가 있습니까?

답변

1

나는 가정 당신은 이미 제품 유형 선택에 기프트 카드를 추가했습니다. 그러나 두 번째 기능에서 동일한 이름을 사용하기 때문에 완전성을 위해 여기에 추가 할 것입니다.

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(); 
     } 
    }); 

}); 
+0

감사합니다 @helgatheviking 그것은 작동합니다. 속성 탭에 "변형에 사용"확인란 필드를 표시하는 방법에 대해 좀 더 자세히 설명해 주시겠습니까? http://prntscr.com/el16t1 이는 제품 유형이 가변 제품 인 경우에만 표시됩니다. –

+0

내가 추가 한 스크립트를 참조하십시오. – helgatheviking

+0

감사합니다. 너무 많이 @helgatheviking –

관련 문제