Getting category of woocommerce product
- by admin
- 0
Call the hook in product displaying page content-product.php
do_action( ‘woocommerce_template_loop_category_title’ );
Otherwise:add below code
global $post;
$cats= get_the_terms( $post->ID, ‘product_cat’ );
$product_cat_id = $cats->term_id;
echo $product->get_categories( ‘Category name ‘, ‘<span class=”posted_in”>’ . _n( ”, ”, sizeof( get_the_terms( $post->ID, ‘product_cat’ ) ), ‘woocommerce’ ) . ‘ ‘, ‘.</span>’ );
Call the hook in product displaying page content-product.php do_action( ‘woocommerce_template_loop_category_title’ ); Otherwise:add below code global $post; $cats= get_the_terms( $post->ID, ‘product_cat’ ); $product_cat_id = $cats->term_id; echo $product->get_categories( ‘Category name ‘, ‘<span class=”posted_in”>’ . _n( ”, ”, sizeof( get_the_terms( $post->ID, ‘product_cat’ ) ), ‘woocommerce’ ) . ‘ ‘, ‘.</span>’ );
Call the hook in product displaying page content-product.php do_action( ‘woocommerce_template_loop_category_title’ ); Otherwise:add below code global $post; $cats= get_the_terms( $post->ID, ‘product_cat’ ); $product_cat_id = $cats->term_id; echo $product->get_categories( ‘Category name ‘, ‘<span class=”posted_in”>’ . _n( ”, ”, sizeof( get_the_terms( $post->ID, ‘product_cat’ ) ), ‘woocommerce’ ) . ‘ ‘, ‘.</span>’ );