Skip to content

Instantly share code, notes, and snippets.

@cristacheda
Created February 27, 2017 19:13
Show Gist options
  • Save cristacheda/3a5c8f09f031e0c1b420be9352a0c247 to your computer and use it in GitHub Desktop.
Save cristacheda/3a5c8f09f031e0c1b420be9352a0c247 to your computer and use it in GitHub Desktop.
woocommerce if product is in category
//Check category
global $post;
$terms = wp_get_post_terms( $post->ID, 'product_cat' );
foreach ( $terms as $term ) $categories[] = $term->slug;
if ( in_array( 'sacouri', $categories ) ) {
echo "<div style='display: none;'>sacouri</div>";
} elseif ( in_array( 'camasi', $categories ) ) {
echo "<div style='display: none;'>camasi</div>";
} elseif ( in_array( 'pantofi', $categories ) ) {
echo "<div style='display: none;'>pantofi</div>";
} else {
echo "<div style='display: none;'>nocat</div>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment