douzhuo6931 2015-03-03 06:38
浏览 55

is_product改变销售闪存woocommerce无法正常工作

Can someone explain to me ?

i wanna simply change sale-flash in woocommerce into 2 type of text, one is "sale", and other is "rent"..

it's working for page that display category of products,,but not working for display a single product..

here's the code

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

When i access the page of category,,for every product with sale category shows "Sale!" text on the flash,and "Rent!" on the flash for every product with rental category,,,,

but when i click the product with rental category to view their detail, flash still shows "Sale!" text..

  • 写回答

1条回答 默认 最新

  • doupu1949 2015-03-03 06:58
    关注

    You can't use is_product_category() in a single product page...because it's not a product category page. You need to find the actual category that the product is in, and output the sale flash based on that. You can check a post category by using get_the_terms().

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

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示