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
}

 

Disclaimer: The content in this post is for educational purposes only. Always remember to take a backup before doing any of the suggested steps just to be on the safe side.
Referral Note: When you purchase through a referral link (if any) on this page, we may earn a commission.
If you're feeling thankful, you can buy me a coffee or a beer