1

The thing is that I wanted to add a hook on single page, so that if the product hasn't got a price then add a custom button that leads to contact page. The validation I make on the hook is that if I am on single product page. Everythings works fine but the thing is that I also see the button on related products beneath. How I can hook only inside the current single product that I am looking and not the single product page? This is the code I use now:

add_filter('woocommerce_empty_price_html', 'custom_free_price_text');

function custom_free_price_text($product)
{
   if (is_product()) {
       global $product;
       $price = $product->get_price();
        if ($price == '') {
            ob_start();
           //my code..
        }
    }
}
Bariock
  • 51
  • 7
  • 2
    Related: [WooCommerce: Show price suffix only on single product Page - Not for related products](https://stackoverflow.com/questions/60462833/woocommerce-show-price-suffix-only-on-single-product-page-not-for-related-pro/60462979#60462979) – 7uc1f3r Jul 28 '20 at 14:03
  • 2
    Thanks. Actually I Found a solution on the link you posted. I added another validation $woocommerce_loop['name'] != 'related'). Simple as that. Thanks! – Bariock Jul 28 '20 at 14:18
  • Use the hook `woocommerce_after_add_to_cart_button` like in [this thread](https://stackoverflow.com/questions/63113019/additional-custom-button-for-specific-single-product-page-in-woocommerce/63113348#63113348) – LoicTheAztec Jul 28 '20 at 15:26

0 Answers0