WooCommerce - Overriding billing state and post code on existing checkout fields

后端 未结 2 1272
独厮守ぢ
独厮守ぢ 2020-12-01 22:55

I can\'t find the way to ovveride billing state and post code.

How can I edit the other parts of existing billing fields like billing state and post code?

Th

2条回答
  •  情书的邮戳
    2020-12-01 23:33

    //-------------------------- OVERRIDING BILLING STATE FIELD -------------------------------//
    
    //Removing previous one by using unset
    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['billing']['billing_state']);
    
         return $fields;
    }
            
    
    add_filter( 'woocommerce_default_address_fields' , 'art_override_default_address_fields' );
    
    function art_override_default_address_fields( $address_fields ) {
        // @ for state
        $address_fields['Billing_State']['type'] = 'text';
        $address_fields['Billing_State']['class'] = array('form-row-wide');
        $address_fields['Billing_State']['required'] = true;
        $address_fields['Billing_State']['label'] = __('State', 'my_theme_slug');
        $address_fields['Billing_State']['placeholder'] = __('Enter state', 'my_theme_slug');
    
        return $address_fields;
    }
    

提交回复
热议问题