WooCommerce Change Form Labels and Remove Fields

后端 未结 3 1140
终归单人心
终归单人心 2021-01-20 06:16

I\'m trying to customise WooCommerce checkout page, how can I edit field labels?

Also, how can I remove 2 fields from the form? I don\'t need Company an

相关标签:
3条回答
  • 2021-01-20 06:29

    Here is a working hook that you need to add into your theme's functions.php file

    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;
    }
    
    0 讨论(0)
  • 2021-01-20 06:37

    Updating for future readers -

    WooCommerce Docs now has a codex article on Customizing checkout fields using actions and filters which looks rather comprehensive.

    The only additional point I will make is that as of WooCommerce 3.5.1 there is a small trick to using Billing/Shipping_Address_2 Labels, as addressed in my answer to this question.

    0 讨论(0)
  • 2021-01-20 06:43

    I recommend making a custom plugin that modifies this so you can easily upgrade WooCommerce at a later date.

    In your custom plugin, implement some of the code found on here: http://wcdocs.woothemes.com/snippets/tutorial-customising-checkout-fields-using-actions-and-filters/

    For example, to remove Company and State:

    // 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;
    }
    

    If you need help making a Plugin, I made a guide on how to add custom fields to the Product page. I think it might be helpful in this context. http://www.xatik.com/2013/02/06/add-custom-form-woocommerce-product/

    0 讨论(0)
提交回复
热议问题