Check if Product Belongs to a Product Category or Tag

Check if Product Belongs to a Product Category or Tag WooCommerce support to any WordPress theme:

if( has_term( 4, ‘product_cat’ ) ) {
 // do something if current product in the loop is in product category with ID 4
}
if( has_term( array( ‘sneakers’, ‘backpacks’ ), ‘product_cat’, 50 ) {
 // do something if product with ID 50 is either in category “sneakers” or “backpacks”
} else {
 // do something else if it isn’t
}
if( has_term( 5, ‘product_tag’, 971 ) ) {
 // do something if product with ID = 971 has tag with ID = 5
}
See also  Display Product Gallery Vertically On Single Product Page

Leave a Reply