At some point you will need to check if a product has a specific product tag.
This is useful in case you want to treat some products differently than others.
Here’s some background information.
As we were working on paid addons for our WordPress Sandbox Service - WPSandbox.net site we realized that we should tag some of the virtual products that we set up in WooCommerce. Those specific virtual products will receive some sort of license key or token.
To get that token generated some custom code had to call an external API service for each product that had the tag.
Here’s how to check if the current product or its parent product have a certain WooComerce product tag
$product_id = $product->get_id();
$parent_id = $product->get_parent_id();if ( has_term( 'some_tag', 'product_tag', $parent_id ? $parent_id : $product_id ) ) {
// do something here
}