【问题标题】:Display loop product category items description below their title in WooCommerce在 WooCommerce 中的标题下方显示循环产品类别项目描述
【发布时间】:2021-07-11 13:09:01
【问题描述】:

我想知道如何在 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);

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

【问题讨论】:

标签: php wordpress woocommerce hook-woocommerce taxonomy-terms


【解决方案1】:

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

术语链接内:

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 文件中。经过测试并且可以工作。

【讨论】:

    猜你喜欢
    • 2021-10-09
    • 2018-06-14
    • 1970-01-01
    • 1970-01-01
    • 2022-09-23
    • 1970-01-01
    • 1970-01-01
    • 2018-07-19
    • 1970-01-01
    相关资源
    最近更新 更多