Skip to content

Instantly share code, notes, and snippets.

@technoknol
Last active September 6, 2019 14:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save technoknol/871a169b6238fceec08a to your computer and use it in GitHub Desktop.
Save technoknol/871a169b6238fceec08a 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