2014-02-26 5 views
0

, 나는 제품에 나열된 어떤 범주에 따라 특정 탭의 내용을 표시하기 위해 노력하고있어Woocommerce 조건부 제품 탭

내가 정의 "사이즈 차트"탭을 생성하고, 예를 들어 보여주고 싶은 한 자 :.

  • 제품이 제품은 "액세서리"카테고리에있을 때 "의류"카테고리
  • 없음 크기 차트에있을 때 제품이 '신발'카테고리의
  • 의류 사이즈 차트 신발 사이즈 차트.

나는이 같은 사용자 지정 탭을 만들었습니다

function woo_tab_content() { 

    echo 'This is the size chart'; 

} 

사람이에 조건문을 추가하는 방법을 알고 있나요 :

add_filter('woocommerce_product_tabs', 'woo_rename_tabs', 98); 

function woo_rename_tabs($tabs) { 

    $tabs['new_tab'] = array(
    'title'  => __('Size Chart', 'woocommerce'), 
    'priority' => 55, 
    'callback' => 'woo_tab_content' 
); 

return $tabs; 

} 

는 다음과 같이 사용자 정의 탭 내용을 추가 어떤 카테고리의 상품이 들어 있는지에 따라 어떤 내용이 표시 될지 지정하는 코드 ie

is_product_category('footwear') 

고마워요! woo_tab_content 기능 간단한 그것이이이 싶습니다 그래서 위 한 일을 추가하려면에

답변

0

:

function woo_tab_content() { 

global $post; 
$terms = wp_get_post_terms($post->ID, 'product_cat'); 
foreach ($terms as $term) $categories[] = $term->slug; 

if (in_array('clothing', $categories)) { 

    echo 'this is the clothing tab content!'; 

} elseif (in_array('shoes', $categories)) { 

    echo 'this is the shoes tab content!'; 

} else { 
    echo 'all other tabs'; 
} 

} 

그것은집니다 :

function woo_tab_content() { 

    if (is_product_category('footwear')){ 

     echo 'This is the size chart'; 

    } else { 

     //do something else 

    } 

} 
0

좋아, 나는 다음과 같은 코드를 사용하여 그것을 해결하기 위해 관리 is_product_category는 단일 제품 페이지에서 작동하지 않습니다. 카테고리 페이지 자체에만 해당됩니다.