woocommerce get product categories

86

global $product;
$product->get_id();
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
foreach ($terms as $term) {
    $product_cat_id = $term->term_id;
    break;
}
$terms = get_the_terms( $product_id, 'product_cat' );
foreach ($terms as $term) {
    $product_cat_id[] = $term->term_id;
}

Comments

Submit
0 Comments