2014-05-12 4 views
1

WooCommerce에서 제품 범주에 대한 특정 Woo 템플릿을 만들려고합니다.카테고리 별 WooCommerce 사용자 정의 테마

여기 안내를 따르려고했지만 나에게 적합하지 않습니다. Woocommerce single product - template by categories

나는 또한 이것을 발견했지만 작동시키지 못했습니다. http://wordpress.org/support/topic/plugin-woocommerce-excelling-ecommerce-a-custom-single-product-template

내 테마에는 재정의하려는 특정 템플릿 파일이있는 woocommerce 폴더가 있습니다. 여기

theme/woocommerce/single-product.php 
theme/woocommerce/content-single-product.php 
theme/woocommerce/content-single-product-custom-1.php 

는 타겟팅 할 특정 제품에 대한 구애에 나는 사용자 정의-1 카테고리 설정이 단일 product.php

<?php if (is_product_category('custom-1')) { 
    wc_get_template_part('content', 'single-product-custom-1'); 
    } 
    elseif (is_product_category('promise') { 
    wc_get_template_part('content', 'single-product-custom-2'); 
    } 
    else{ 
    wc_get_template_part('content', 'single-product'); 
    } 
?> 

의 일부입니다.

content-single-product-custom-1.php을 편집 할 때 아무 것도 변경되지 않습니다. 그러나 content-single-product.php를 변경하면 해당 내용이 표시됩니다.

왜 내 제품 카테고리를 타겟팅 할 수 없습니까?

미리 감사드립니다.

답변

1

is_product_category()is_category() 또는 is_tax() Wordpress 함수와 동일하게 동작합니다. 즉, 범주 아카이브 페이지 (이 경우 사용자 지정 분류 아카이브 페이지)가 표시되는지 확인합니다. 그리고 당신은 하나의 게시물 페이지에 있습니다, has_term() (현재 게시물에 주어진 용어가 있는지 확인) 또는 get_the_terms() (게시물에 첨부 된 분류의 용어를 검색하는)과 같은 기능을 사용할 수 있습니다. WooCommeerce에서 분류법 'product_cat'입니다.


<?php 
    if (has_term('custom-1', 'product_cat')) { 
     wc_get_template_part('content', 'single-product-custom-1'); 
    } elseif (has_term('promise', 'product_cat')) { 
     wc_get_template_part('content', 'single-product-custom-2'); 
    } else { 
     wc_get_template_part('content', 'single-product'); 
    } 
?> 
+0

를 참조 할 수 있습니다 내가 제대로 분류 조건을 추가 아니에요 가능할 것이다 ... 난 당신의 코드를 시도했지만 여전히 작동하지 않습니다? 나는 "custom-1"을 우 카테고리의 카테고리로 추가하려고 시도했지만 아직 태그로 추가하려하지 않았습니다. 게시물 ID 번호를 통해 내 맞춤 테마를 타겟팅 할 수 있습니까? – NateW

+0

그래서 저는 모든 것을 더 잘 이해하려고 노력하고 있습니다 ... 그래서 wooCommerce는 taxonomy 용어 'product_cat'을 추가하고 다른 용어는 카테고리 용어를 기반으로합니다. – NateW

+0

당신이 루프 외부에 있다면'print_r (get_the_terms ($ post-> id, 'product_cat'));'를 사용하거나'print_r (get_the_terms ($ product-> ID, 'product_cat')); 'product_cat'분류가 제품에 올바르게 첨부되었는지 확인하기 위해 'single-product.php'템플릿의 ' 출력을 얻지 못하면 잘못 처리합니다. – Danijel

0

제품 본체 클래스의 product_cat_CATEGORYNAME 기간 toinclude 당신의 functions.php 파일이 추가.

function woo_custom_taxonomy_in_body_class($classes){ 
if(is_singular('product')) 
{ 
    $custom_terms = get_the_terms(0, 'product_cat'); 
    if ($custom_terms) { 
     foreach ($custom_terms as $custom_term) { 
      $classes[] = 'product_cat_' . $custom_term->slug; 
     } 
    } 
} 
return $classes; 
} 

add_filter('body_class', 'woo_custom_taxonomy_in_body_class'); 

product_cat 기간이 지금

관련 문제