Dipak Kumar Pusti
Dipak Kumar Pusti

Reputation: 1723

WooCommerce conditional tag for particular product

WooCommerce Conditional Tags page suggests that we can find when a product page is running,

but unlike is_single it does not accepts any parameter to go for any specific product name or slug.

I want to run a script only for a specific product suppose,

http://localhost/realtour/product/demo-tour-package/

I want to run a script on init action hook and check for a specific product. How can I achieve this ?

Upvotes: 2

Views: 771

Answers (1)

rock3t
rock3t

Reputation: 2233

is_product is simply a wrapper to is_singular('product')

To check for specific product, you need to check for either ID or permalink.

if (is_product()) {

    if (basename(get_permalink()) == 'demo-tour-package') {

        # ...
    }
}

Upvotes: 2

Related Questions