I want to check the category of WooCommerce products in function.php.
That is my code:
function for_preorder()
{
///// DISPLAY something if category id = 50
}
add_action('woocommerce_before_single_product','for_preorder');
How to check for a product category for a WooCommerce product?
2
Answers
Or, if you pass the product ID in the
for_preorder()
function, you can do:You can use
has_term()
WordPress conditional function to check for a category like:Code goes in functions.php file of the active child theme (or active theme). Tested and works.