Adding Conditional to WooCommerce Display Product Logic – Category Conditionals
Many times we want to make one or more categories display in different way in our WooCommerce shop. WordPress and WooCommerce API give us possibilities of using hooks in conditionals to display content elements we want. Lets imagine that we want add or remove something if product belong to certain category ( for example we want to have additional info about the possibility to check extra info about the product. We can add something like this
add_action( 'woocommerce_product_meta_start', 'our_extra_content_single_category_slug' );
function our_extra_content_single_category_slug() :
if (is_product() && has_term(0, 'product_cat'))
{
echo '<div><p>Our extra info text</p></div>';
}
endif;
In this example ‘product cat’ is an array of our categories and ‘0’ is the id of a category to which we want add our additional html content.