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

WooCommerce产品内容区域对应的shortcode(短代码)是什么?

WooCommerce 产品内容区域短代码解决方案

WooCommerce 官方没有提供原生的单产品完整内容区域短代码,Elementor 中的产品内容 Widget 是平台独立封装的功能模块,没有对外公开对应的通用短代码,你可以根据使用场景选择以下两种方案实现需求:

  • 如果你需要输出和 WooCommerce 默认单产品页完全一致的内容区域,可自定义注册专属短代码:
    将下方代码添加到当前站点主题/子主题的 functions.php 文件中:
    // 自定义产品内容短代码,调用格式 [custom_product_content id="产品ID"]
    add_shortcode('custom_product_content', function ($atts) {
        $atts = shortcode_atts(['id' => ''], $atts);
        if (empty($atts['id']) || !class_exists('WooCommerce')) return '';
        $product = wc_get_product($atts['id']);
        if (!$product instanceof WC_Product) return '';
        
        ob_start();
        wc_get_template_part('content', 'single-product');
        return ob_get_clean();
    });
    
    代码添加完成后,直接使用短代码 [custom_product_content id="xxx"] 调用即可,将 xxx 替换为目标产品的数字ID。
  • 如果你要调用的是你已经在 Elementor 中配置好样式的产品内容模块,可将对应Widget保存为Elementor全局模板,获取模板ID后使用Elementor原生短代码调用:
    [elementor-template id="xxx"],将 xxx 替换为你保存的全局模板数字ID即可,输出效果和Elementor编辑器内的配置完全一致。

附常用WooCommerce产品类原生短代码,可直接调用:

  • 单产品卡片:[product id="产品ID"]
  • 产品加购按钮:[add_to_cart id="产品ID"]
  • 产品价格:[product_price id="产品ID"]
  • 产品添加到购物车URL:[add_to_cart_url id="产品ID"]

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.05 23:00:03