我想知道如何在 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);
但这不会在商店页面的类别标题下显示猫的描述,我们将不胜感激。
最佳答案
要在标题下方显示循环产品类别项目描述,请使用以下选项之一:
术语链接内:
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 文件中。经过测试并有效。
关于php - 在 WooCommerce 中的标题下方显示循环产品类别项目描述,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67126379/