我想知道如何在woocommerce shop by category页面的类别标题下添加类别描述?这是我尝试过的。“
function woocommerce_after_shop_loop_item_title_short_description() {
global $product;
if ( ! $product->post->post_excerpt ) return;
?>
<div itemprop="description">
<?php echo apply_filters( 'woocommerce_short_description', $product->post->post_excerpt ) ?>
</div>
<?php
}
add_action('woocommerce_after_shop_loop_item_title', 'woocommerce_after_shop_loop_item_title_short_description', 5);但这并没有在商店页面的类别标题下显示猫的描述,任何帮助都将不胜感激。

发布于 2021-04-16 22:09:20
要在标题下显示循环产品类别项目说明,请使用以下方法之一:
在术语链接中:
add_action('woocommerce_after_subcategory_title', 'display_short_description_after_shop_loop_item_title', 10 );
function display_short_description_after_shop_loop_item_title( $category ) {
if ( $description = $category->description ) {
echo '<p class="'. $category->slug .' cat-description" itemprop="description">' . $description . '</p>';
}
}在术语链接之外:
add_action('woocommerce_after_subcategory', 'display_short_description_after_shop_loop_item_title', 20 );
function display_short_description_after_shop_loop_item_title( $category ) {
if ( $description = $category->description ) {
echo '<p class="'. $category->slug .' cat-description" itemprop="description">' . $description . '</p>';
}
}代码放在活动子主题(或活动主题)的functions.php文件中。经过测试,效果良好。
https://stackoverflow.com/questions/67126379
复制相似问题