How to change Billing address field label in WooCommerce

前端 未结 2 1489
天涯浪人
天涯浪人 2021-01-03 10:43

In my design i have non standard billing fields label and markup. For example \"Town / City *\" should be \"Province *\".

I have used WOO documentation, and filter <

相关标签:
2条回答
  • 2021-01-03 11:11

    In specific cases you need to use the woocommerce_default_address_fields filter. This filter is applied to all billing and shipping default fields:
    'country', 'first_name', 'last_name', 'company', 'address_1', 'address_2', 'city', 'state' or 'postcode'.

    Here we only use 'city' and 'postcode' as in your code:

    add_filter( 'woocommerce_default_address_fields' , 'override_default_address_fields' );
    function override_default_address_fields( $address_fields ) {
    
        // @ for city
        $address_fields['city']['class'] = array('form-row-first');
        $address_fields['city']['label'] = __('Province', 'woocommerce');
    
        // @ for postcode
        $address_fields['postcode']['label'] = __('Zipcode', 'woocommerce');
    
        return $address_fields;
    }
    

    This is tested and working.

    This code snippet goes on function.php file of your active child theme or theme

    References:

    • Official WooThemes - Customizing checkout fields using actions and filters
    • WooCommerce - Overriding billing state and post code on existing checkout fields
    0 讨论(0)
  • 2021-01-03 11:19

    It's been a while since the OP question, but I faced a similar situation (we use "Department" instead of "Province") and found a solution that doesn't involve coding, which in my case makes things easier. It's the plugin Booster for WooCommerce.

    It ads several other customization possibilities I have yet to try, but tweaking labels works just fine.

    BTW, depending on your server settings it may cause an out-of-memory error upon activation, with WordPress returning a blank page. Temporarily increasing memory allocated to PHP allows it to complete activation.

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