【问题标题】:WooCommerce Change Form Labels and Remove FieldsWooCommerce 更改表单标签并删除字段
【发布时间】:2013-01-27 14:23:32
【问题描述】:

我正在尝试自定义 WooCommerce 结帐页面,如何编辑字段标签?

另外,如何从表单中删除 2 个字段?我不需要Company 和State 字段。

【问题讨论】:

    标签: wordpress woocommerce


    【解决方案1】:

    我建议制作一个自定义插件来修改它,以便您以后可以轻松升级 WooCommerce。

    在您的自定义插件中,实现此处的一些代码:http://wcdocs.woothemes.com/snippets/tutorial-customising-checkout-fields-using-actions-and-filters/

    例如,删除公司和州:

    // Hook in
    add_filter( 'woocommerce_checkout_fields', 'custom_override_checkout_fields' );
    // Our Hooked in function - $fields is passed via the filter
    function custom_override_checkout_fields( $fields) {
        unset($fields['shipping']['shipping_state']);
        unset($fields['shipping']['shipping_company']);
        return $fields;
    }
    

    如果您在制作插件时需要帮助,我制作了有关如何将自定义字段添加到产品页面的指南。我认为这在这种情况下可能会有所帮助。 http://www.xatik.com/2013/02/06/add-custom-form-woocommerce-product/

    【讨论】:

    • 您发布的如何将其制成插件的帖子非常有帮助。谢谢你,好先生!
    • 我很高兴它对某人有所帮助!我自己花了很多时间试图弄清楚这一点。
    【解决方案2】:

    这是一个你需要添加到主题的functions.php文件中的工作钩子

    add_filter( 'woocommerce_checkout_fields' , 'remove_checkout_fields' );
    
    function remove_checkout_fields( $fields ) {
        unset($fields['billing']['billing_state']);
        unset($fields['billing']['billing_company']);
        unset($fields['billing']['billing_country']);
        return $fields;
    }
    

    【讨论】:

      【解决方案3】:

      为未来的读者更新 -

      WooCommerce Docs 现在有一篇关于 Customizing checkout fields using actions and filters 的法典文章,看起来相当全面。

      我要补充的唯一一点是,从 WooCommerce 3.5.1 开始,使用 Billing/Shipping_Address_2 标签有一个小技巧,正如我对 this question 的回答中所述。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-10-16
        • 2016-12-08
        • 1970-01-01
        • 2022-12-17
        • 2017-07-30
        • 2015-12-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多