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..

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
}