Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hemusyl/a56290ba69c02f046a9c0d0ae14e825c to your computer and use it in GitHub Desktop.
Save hemusyl/a56290ba69c02f046a9c0d0ae14e825c to your computer and use it in GitHub Desktop.
Woocommerce get product category list
<?php
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ($terms as $term) {
$product_cat_id[] = $term->term_id;
break;
}
print_r (array_filter( array_unique( $product_cat_id ))) ;
## Please look into the meta.php file in the “templates/single-product/” folder of the WooCommerce plugin.
echo $product->get_categories( ', ', '<span>' . _n( 'Category:', 'Categories:', sizeof( get_the_terms( $post->ID, 'product_cat' ) ), 'woocommerce' ) . ' ', '.</span>' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment