简体   繁体   中英

WooCommerce archive pages add categories before product title

I should need to display categories from the product before the title in Woocommerce archives pages, like it's shown in this image. How can I do that?

在此处输入图像描述

You can use below example to add category above the title. This function will go inside child theme functions.php or parent theme functions.php

/**
* @return add category link and title above the title or below the category
*
*/
function theme_slug_add_category_above_title() {
    global $product;
    echo wc_get_product_category_list( $product->get_id() );
}
add_action( 'woocommerce_shop_loop_item_title', 'theme_slug_add_category_above_title', 9 );

You can get all the list of hooks related to product list on woocommerce/templates/content-product.php and can see the use of wc_get_product_category_list() in woocommerce/templates/single-product/meta.php

Thanks

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM