2015-03-03 57 views
0

有人可以向我解释吗?is_product更改sale-flash woocommerce不起作用

我想简单地改变woocommerce销售闪存分为2类文本的,一个是“销售”等是“租” ..

它的工作对于显示的产品分类页面,,但不工作显示的单品..

这里的代码

<?php 
     if(is_product()){ 
      if (is_product_category('Sale')) { 
       echo apply_filters('woocommerce_sale_flash', '<span class="onsale">' . __('Sale!', 'woocommerce') . '</span>', $post, $product); 
       } 

       if (is_product_category('Rental')) { 
       echo apply_filters('woocommerce_sale_flash', '<span class="onsale">' . __('Rent!', 'woocommerce') . '</span>', $post, $product); 
       } 

     }else{ 
      if (is_product_category()) { 

       if (is_product_category('Sale')) { 
       echo apply_filters('woocommerce_sale_flash', '<span class="onsale">' . __('Sale!', 'woocommerce') . '</span>', $post, $product); 
       } 

       if (is_product_category('Rental')) { 
       echo apply_filters('woocommerce_sale_flash', '<span class="onsale">' . __('Rent!', 'woocommerce') . '</span>', $post, $product); 
       } 
      } 
     } 
    ?> 

当我访问类的页面,,与销售类每一个产品显示“出售!”闪光灯上的文字,以及“Rent!”闪光灯与租金每类产品,,,,

但是当我点击与租赁类产品以查看详细,闪光灯仍然显示“出售!”文字..

回答

0

你不能在一个单一的产品页面中使用is_product_category() ...因为它不是一个产品分类页面。您需要找到该产品所在的实际类别,然后根据该类别输出销售Flash。您可以使用get_the_terms()查看帖子类别。

global $post; 
$terms = get_the_terms($post->ID, 'product_cat'); 
if (in_array('Rental', $terms)) { 
    // do something 
}