nima
nima

Reputation: 97

hide a button from a specific product Tag in Woocommerce product pages

I have Woocommerce WebSite. I need a php code to hide part of html in product details page by a certain Product Tag.

For example if product include "abc" product tag, then hide an html button. I need this code for product details page only.

Upvotes: 1

Views: 365

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 253814

This can be done with Wordpress has_term() conditional function for the 'product_tag' custom taxonomy, like in this example:

// Output some code except for "abc" product tag
if( ! has_term( 'abc', 'product_tag', get_the_id() ) ){
    ?>
    <a href="#">This product has not "abc" tag</a>
    <?php
}

The button will be hidden from products that have "abc" product tag…

Upvotes: 3

Related Questions