You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何仅在WooCommerce主商店页面产品循环后添加文本?

实现WooCommerce主商店首页产品循环后插入自定义文本

可以通过WooCommerce钩子结合WordPress条件判断函数实现需求,将以下代码添加到子主题的functions.php文件或自定义功能插件中即可:

add_action( 'woocommerce_after_shop_loop', 'custom_text_after_shop_loop', 20 );
function custom_text_after_shop_loop() {
    // 同时满足三个条件:主商店页面、未选中产品分类、当前为第一页
    if ( is_shop() && !is_product_category() && !is_paged() ) {
        // 替换为你需要插入的文本或HTML内容
        echo '<div class="shop-custom-desc">
                <p>这里是自定义文本内容,样式可通过CSS自行调整</p>
              </div>';
    }
}

代码说明

  • woocommerce_after_shop_loop:WooCommerce官方钩子,用于在产品循环结束后插入内容,设置优先级20是为了确保在默认循环内容之后加载
  • is_shop():判断当前页面是否为主商店页面
  • !is_product_category():排除选中产品分类的页面
  • !is_paged():排除第二页及以后的分页页面

可选样式调整

如果需要让插入的文本和分类描述样式统一,可以添加自定义CSS:

.shop-custom-desc {
    margin: 2em 0;
    padding: 1.5em;
    background-color: #f8f8f8;
    border-radius: 4px;
    line-height: 1.6;
}

内容的提问来源于stack exchange,提问作者Bart

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 05:32:32