How To Treat Products in Different Categories Differently

Let’s say you want to have a different template for products in different categories. Open up your foxyshop-single-product.php template and enter this code after the product has been initialized:

$product_categories = wp_get_post_terms($product['id'], 'foxyshop_categories', array("fields" => "names"));

Now, you can use some simple logic:

if (in_array('Pets', $product_categories)) {
	//Special Instructions For the Pets category
} else {
	//Instructions For Everyone Else
}

Posted in: Helpful Code Snippets