• Hi Guys,

    Ok I added a hook to show an extra button on the single product page

    add_action(‘woocommerce_after_add_to_cart_button’,’cmk_additional_button’);
    function cmk_additional_button() {
    echo ‘<button type=”submit” class=”button alt”>test</button>’;
    }

    This works and is shown on all products now.

    How can I restrict this so it only shows on single product pages that are within certain categories, for example “Commercial Gym Equipment” only?

    Thank you in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Wrap your echo in

    if( is_category( ID ) ) {
    ...
    }

    where ID is the required category’s id

    Thread Starter Woz Gekko

    (@gekkoshot)

    Thanks, however I got it working with –

    add_action(‘woocommerce_after_add_to_cart_button’, ‘cmk_additional_button’);
    function cmk_additional_button() {

    if ( is_product() && has_term( ‘Commercial Gym Equipment’, ‘product_cat’ ) ) {
    echo ‘<button type=”submit” class=”button alt”>Commercial Finance Available</button>’;
    }
    }

    Thanks for your reply

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Show button for nominated category only?’ is closed to new replies.