• Hi everybody. I changed some fields with this code

    // 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 ) {
         $fields['billing']['billing_city']['placeholder'] = 'London'; /
         $fields['billing']['billing_city']['label'] = 'Region and city';
         $fields['billing']['billing_postcode']['placeholder'] = 'Post 1'; 
         $fields['billing']['billing_postcode']['label'] = 'Number of post'; 
         return $fields;
    }

    So, placeholder is changed, but not a label. How to change LABEl?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Try using the woocommerce_default_address_fields hook instead of the checkoutout fields hook.

    Thread Starter The True Liar

    (@pandakiller)

    It did not hepl. If i changed it than i have problem such a Warning: call_user_func_array() expects parameter 1 to be a valid callback, function 'custom_override_checkout_fields' not found or invalid function name in /home/[name]/[site.name]/www/wp-includes/class-wp-hook.php on line 298

    Can you please post the code you tried?

    Thread Starter The True Liar

    (@pandakiller)

    Sure.
    Before i wrote there it was

    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    
    function custom_override_checkout_fields( $fields ) {
    
    $fields['billing']['billing_city']['placeholder'] = 'London'; 
    $fields['billing']['billing_city']['label'] = 'City and Region';
    $fields['billing']['billing_postcode']['placeholder'] = 'Post no. 1';
    $fields['billing']['billing_postcode']['label'] = 'No. of Post'; 
    
    unset($fields['billing']['billing_company']); 
    unset($fields['billing_company']['billing_company']);
    unset($fields['billing']['billing_state']);
    unset($fields['billing']['billing_billing_address_1']); 
    unset($fields['billing']['billing_address_1']); 
    unset($fields['billing']['billing_address_2']); 
    	 
    return $fields;
    }
    add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
     
    function custom_override_default_address_fields( $address_fields ) {
    $address_fields['billing_address_1']['required'] = false; 
    $address_fields['state']['required'] = false; 
    $address_fields['postcode']['required'] = true; 
    $address_fields['city']['required'] = true; 
     
    return $address_fields;
    }
    

    And after your answer it is

    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    
    function woocommerce_default_address_fields( $fields ) {
    
    $fields['billing']['billing_city']['placeholder'] = 'London'; 
    $fields['billing']['billing_city']['label'] = 'City and Region';
    $fields['billing']['billing_postcode']['placeholder'] = 'Post no. 1';
    $fields['billing']['billing_postcode']['label'] = 'No. of Post'; 
    
    unset($fields['billing']['billing_company']); 
    unset($fields['billing_company']['billing_company']);
    unset($fields['billing']['billing_state']);
    unset($fields['billing']['billing_billing_address_1']); 
    unset($fields['billing']['billing_address_1']); 
    unset($fields['billing']['billing_address_2']); 
    	 
    return $fields;
    }
    add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
     
    function custom_override_default_address_fields( $address_fields ) {
    $address_fields['billing_address_1']['required'] = false; 
    $address_fields['state']['required'] = false; 
    $address_fields['postcode']['required'] = true; 
    $address_fields['city']['required'] = true; 
     
    return $address_fields;
    }
    

    What I was meant was to try the hook woocommerce_default_address_fields rather than the checkout hook, not to change the name of your function, since billing address fields are generated from that function and in some cases that is the only way to change the default fields for billing addresses.

    A couple of notes: in your revised code, your first function is not corresponding to your named function in your filter `add_filter( ‘woocommerce_checkout_fields’ , ‘custom_override_checkout_fields’);

    function woocommerce_default_address_field( $fields ) {`

    in this case woocommerce_checkout_fields is the hook and your function needs to be named the same as your second parameter.

    Then, you are referencing the woocommerce_default_address_fields hook in the second filter of your code but it is not going to recognize $address_fields is why you are getting the invalid callback. Use $fields for both filters.

    The only other suggestion that I could make about your labels not changing is that you might try changing the code to
    $fields[‘billing’][‘billing_city’][‘label’] = ‘__(‘City and Region’, ‘woocommerce’);

    • This reply was modified 7 years, 8 months ago by katdidit.
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Fields’ is closed to new replies.