在 WooCommerce 中的标题下方显示循环产品类别项目描述

问题描述

我想知道如何在woocommerce商店按类别页面的类别标题添加类别描述?这是我尝试过的"

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);

但这并没有在商店页面的类别标题显示猫的描述,任何帮助将不胜感激。

enter image description here

解决方法

要在标题下方显示循环产品类别项目描述,请使用以下方法之一:

在术语链接内:

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',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 文件中。经测试有效。