George
George

Reputation: 540

Woocommerce - if is specific product

I need to make some different things for each product page in Woocommerce, so I was thinking to use something like:

is_product('My Product Name')

But no luck with it. How could I do it?

Upvotes: 1

Views: 12253

Answers (2)

UncaughtTypeError
UncaughtTypeError

Reputation: 8712

Product titles are subject to change.

Check against an immutable reference instead, like the product ID:

is_single(31950)

Verify that you are checking a product page as well:

is_single(31950) && is_product()

Upvotes: 9

rgdesign
rgdesign

Reputation: 515

is_product - Returns true when viewing a single product. So thats not what you need.

You need to check if the product title is x.

Somethig like: $product_title = get_the_title(); if( $product_title == "your title") // do something

Upvotes: 3

Related Questions