skip to Main Content

Need help, I want to echo “sale” on the woocommerce product page on top of product title if the product is on the “store-pickup” product category.

Tried using the below code, but WordPress throws an error

add_action( 'woocommerce_single_product_summary', 'show_store_pickup', 1 );
      function show_store_pickup() {
        global $product; 
     if (is_product_category( 'store-pickup' )) { 
      echo "Sale!";  

}

2

Answers


  1. Can you please check with “woocommerce_before_single_product_summary” hook. that might be help you. also check the result of is_product_category() is coming properly or not.

    Login or Signup to reply.
  2. Try the follows code –

    add_action( 'woocommerce_single_product_summary', 'show_store_pickup', 1 );
    function show_store_pickup() {
        global $product; 
        if ( has_term( 'store-pickup', 'product_cat', $product->get_id() ) ) 
            echo __( "Sale!", "text-domain" );  
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search