我正在尝试在商店页面的产品图片下显示每个产品类别 .
Here's the current page
Here's where I want to display the category name
我已尝试使用以下代码,但它似乎不能从functions.php文件中获取当前的产品类别 .
And here it comes...
function sv_add_text_under_wc_shop_image() {
echo $product->get_categories( ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', sizeof( get_the_terms( $post->ID, 'product_cat' ) ) ) . ' ', '</span>' );
}
add_action( 'woocommerce_before_shop_loop_item_title', 'sv_add_text_under_wc_shop_image', 10 );
1 回答
将content-product.php的副本复制到您的子主题并找到以下行:
在它之后添加: