Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tradesouthwest/6a02060cb18768b433802aee34f75950 to your computer and use it in GitHub Desktop.
Save tradesouthwest/6a02060cb18768b433802aee34f75950 to your computer and use it in GitHub Desktop.
Check if single product has a specific product category.
<?php
// checking terms since wc_product are not post terms
function product_cat_contingencies()
{
global $post;
// get the product category term objects
$terms = wp_get_post_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ) $categories[] = $term->slug;
if( in_array('custom-tarps', $categories) ) {
return true;
} else {
return false; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment