I want to add the product's category between the title and the price of each product. As long as I edited the archive-product.php file with codes i found here, nothing seemed to work. I created a copy of the file on the active theme too.
we can use 'woocommerce_after_shop_loop_item_title' action for this case
function product_category_in_shop_loop() {
global $product;
$product_id = $product->get_id();
$cat = wp_get_post_terms($product_id, 'product_cat', array('fields' => 'names'));
if( !empty($cat[0]) ){
echo '<p class="catil">'.$cat[0].'</p>';
}
}
add_action( 'woocommerce_after_shop_loop_item_title', 'product_category_in_shop_loop', 40 );
code goes to child theme function.php.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.