Solution for : WooCommerce - get category for product page
A WC product may belong to none, one or more WC categories. Supposing you just want to get one WC category id.
1 2 3 4 5 6 | global $post ; $terms = get_the_terms( $post ->ID, 'product_cat' ); foreach ( $terms as $term ) { $product_cat_id = $term ->term_id; break ; } |
Please look into the meta.php file in the "templates/single-product/" folder of the WooCommerce plugin.
1 | echo $product ->get_categories( ', ' , '<span class="posted_in">' . _n( 'Category:' , 'Categories:' , sizeof( get_the_terms( $post ->ID, 'product_cat' ) ), 'woocommerce' ) . ' ' , '.</span>' ); |
No comments:
Post a Comment