Support » Plugin: WooCommerce » Billing address 1 placeholder

  • Resolved 9metis

    (@9metis)


    Hi,

    I am trying to replace the default placeholder of the billing address 1 (#billing_address_1) but can’t get the below code in my child theme’s functions.php to work. I’ve managed to replace all other placeholders. Anyone have any ideas? Thanks in advance!

    function custom_rename_wc_checkout_fields( $fields ) {
    $fields['billing']['billing_address_1']['placeholder'] = 'Street Address';
    $fields['billing']['billing_address_1']['label'] = '';
    $fields['billing']['billing_city']['placeholder'] = 'City';
    $fields['billing']['billing_city']['label'] = '';
    $fields['billing']['billing_postcode']['placeholder'] = 'ZIP';
    $fields['billing']['billing_postcode']['label'] = '';
    $fields['billing']['billing_state']['placeholder'] = 'State';
    $fields['billing']['billing_state']['label'] = '';
    $fields['billing']['billing_country']['placeholder'] = 'Country';
    $fields['billing']['billing_country']['label'] = '';
    $fields['billing']['billing_phone']['placeholder'] = 'Phone number';
    $fields['billing']['billing_phone']['label'] = '';
    $fields['billing']['billing_email']['placeholder'] = 'Email address';
    $fields['billing']['billing_email']['label'] = '';
    $fields['billing']['order_comments']['placeholder'] = 'Additional information';
    $fields['billing']['order_comments']['label'] = '';
    return $fields;
    }
Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi @9metis!

    Use the following:

    add_filter('woocommerce_default_address_fields', 'wc_override_address_fields');
    function wc_override_address_fields( $fields ) {
    $fields['address_1']['placeholder'] = 'Street Address';
    return $fields;
    }

    Cheers!

    Thanks @rynald0s worked perfectly! Can you tell me why the first code didn’t work?

    Plugin Support Rynald0s

    (@rynald0s)

    Automattic Happiness Engineer

    Hi @9metis!

    You’re very welcome!

    I believe you may have used a different filter other than woocommerce_default_address_fields

    Glad it’s working though.

    Cheers!

    Hi @rynald0s I was wondering if you can help with a related issue. For some reason, the placeholder for country is now missing (I don’t remember doing anything to change this). The code I first published above doesn’t seem to work for country.

    Plugin Support Jesse Pearson

    (@jessepearson)

    Automattic Happiness Engineer

    @9metis The country field should not have a placeholder, as it is a dropdown/select field. By default it does not have one:

    
    			'country'    => array(
    				'type'         => 'country',
    				'label'        => __( 'Country', 'woocommerce' ),
    				'required'     => true,
    				'class'        => array( 'form-row-wide', 'address-field', 'update_totals_on_change' ),
    				'autocomplete' => 'country',
    				'priority'     => 40,
    			),
    


    Link to image: https://cld.wthms.co/HRAbcV

    If this field is a text field, it may be your theme making it a text field, which would cause a placeholder not to show.

    Thanks @jessepearson it used to have a placeholder just like the State drop down. I was able to use the same code for the State drop down which worked but just puzzled as to why it won’t work for the Country drop down.

    Plugin Support Jesse Pearson

    (@jessepearson)

    Automattic Happiness Engineer

    @9metis I do not believe the Country ever had a placeholder, however, I do see now that the State drop down does have this available. The code can be found here:
    https://github.com/woocommerce/woocommerce/blob/3.7.0/includes/wc-template-functions.php#L2688-L2740

    This is what outputs the two fields. You can see in lines 2721 and 2725, which is part of the State output, there are args for the placeholder.

    If you go up to lines 2695 and 2699, which is the output for the Country, there is no such argument.

    Now, at the top, if you click the Blame button and view those same lines, you can see they have not been changed in years for the Country. It may be possible that something in a theme allowed for this change for you.

    @jessepearson thanks I think that makes sense!

Viewing 8 replies - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.