Woocommerce: Conditional Tag for a specific Single Product in Shop

Created on 25 Jul 2012  ·  3Comments  ·  Source: woocommerce/woocommerce

Hi everyone,

I am using the widget logic plugin to display different text widgets in different product categories - so far so good, this works excellent, by simply adding the product category conditional tag --> is_product_category('xyz') into the widget logic field below the according widget.

However, I was not able to make this possible for a specific product in woocommerce. Using this conditional tag: is_product () will solely then show the widget in ALL product pages.

Is there any way to target a specific product, using the unique product ID?

This is what I currently have for regular php:

function check_specific_page() {
global $product;

if( $product->id == 1 && is_product() )
    die( 'I\'m showing only on single product page with id 1' );

}

Adding $product->id == 1 && is_product() into the widget logic field however does not work.

I really hope you can help...basically what I need is the conditional tag for a specific product.

Thanks so much,
Rich

Most helpful comment

Use is_single - its a WP conditional.

All 3 comments

Use is_single - its a WP conditional.

Worked like a charm! Great! I really searched for hours and this simple ID works - so to target a single product, simply use is_single(ID)

Works like charm... is_single(ID) ... just like @richangel, i have dived into different articles for hours and i am glad i opened this link. Thanks so much @mikejolley

Was this page helpful?
0 / 5 - 0 ratings