【问题标题】:Display ACF fields on WooCommerce single product page在 WooCommerce 单品页面上显示 ACF 字段
【发布时间】:2020-07-06 05:36:09
【问题描述】:

我使用 ACF 创建了一个自定义字段,我想在我的 WooCommerce 单一产品页面中显示它。我该怎么做?

【问题讨论】:

    标签: woocommerce advanced-custom-fields hook-woocommerce


    【解决方案1】:

    您需要找出代表应该显示 ACF 字段的位置的钩子,例如将WooCommerce Visual Hook Guide 用于单个产品页面。

    示例

    add_action( 'woocommerce_after_single_product_summary', 'view_acf_field_for_single_product', 10 );
    
    function view_acf_field_for_single_product(){  
      if (function_exists('the_field')){
        the_field('field_name');
      }
    
    }
    

    本文改编自https://support.advancedcustomfields.com/forums/topic/acf-with-woocommerce/

    【讨论】:

    • 嗨,感谢您的输入我需要用我的字段名称替换“the_field”吗?我还需要替换这个“view_acf_field_for_single_product”吗?我没有这方面的经验,这就是我问的原因。
    • the_field() 是 ACF 提供的函数。您需要更改的是 field_name,因为这是您在 ACF 中指定的字段。函数名也可以自己选择,但要一致
    猜你喜欢
    • 2021-08-02
    • 2021-11-26
    • 1970-01-01
    • 2019-01-26
    • 1970-01-01
    • 2021-05-15
    • 1970-01-01
    • 2020-09-01
    相关资源
    最近更新 更多