Woocommerce default placeholder not gone in checkout form

I’m using woocommerce_checkout_fields to change labels and fields.Below is my code

function custom_override_checkout_fields($fields) {


     $fields['billing']['billing_first_name'] = array(
            'label' => '',
            'placeholder' => _x('First Name*', 'placeholder', 'woocommerce'),
            'required' => true,
            'class' => array('checkout-billing-first-name')
        );
        $fields['billing']['billing_last_name'] = array(
            'label' => '',
            'placeholder' => _x('last Name*', 'placeholder', 'woocommerce'),
            'required' => true,
            'class' => array('checkout-billing-last-name')
        );
        $fields['billing']['billing_company'] = array(
            'label' => '',
            'placeholder' => _x('Company Name', 'placeholder', 'woocommerce'),
            'required' => false,
            'class' => array('checkout-billing-company')
        );
        $fields['billing']['billing_address_1'] = array(
            'label' => '',
            'placeholder' => _x('Address(Line 1)*', 'placeholder', 'woocommerce'),
            'required' => true,
            'class' => array('checkout-billing-addressL1')
        );
         $fields['billing']['billing_address_2'] = array(
            'label' => '',
            'placeholder' => _x('Address(Line 2)*', 'placeholder', 'woocommerce'),
            'required' => false,
            'class' => array('checkout-billing-addressL2')
        );

        return $fields;
    }

    add_filter('woocommerce_checkout_fields', 'custom_override_checkout_fields');

Everything works fine but placeholder for billing address 1 and billing address 2 is changing for only
in loading i.e after page is loaded default placeholder are shown.

Related posts

Leave a Reply

3 comments

  1. Try use filter woocommerce_default_address_fields.

    For example:

    function pawelprotas_wc_default_address_fields($fields){
        $fields['address_1']['placeholder'] = __('Street address *', 'loft');
        $fields['address_2']['placeholder'] = __('Apartment, suite, unit etc.', 'loft');
    
        return $fields;
    }
    
    add_filter('woocommerce_default_address_fields', 'pawelprotas_wc_default_address_fields');
    
  2. First add the below filter to prevent replace placeholder from JS.

    add_filter( 'woocommerce_country_locale_field_selectors' , 'override_billing_checkout_fields', 10, 1 );
    
    function override_billing_checkout_fields( $locale_fields ) {
        $locale_fields = array(
            'address_1' => '',
            'address_2' => ''
        );
        return $locale_fields;
    }
    

    Then use the below filter

    add_filter('woocommerce_checkout_fields', 'custom_override_checkout_fields');
    function custom_override_checkout_fields($fields)
    {
        $fields['billing']['billing_address_1']['placeholder'] = __( 'Address 1', 'woocommerce' );
        return $fields;
    }
    
  3. You can also change the default placeholders:

    add_filter('woocommerce_checkout_fields', 'custom_override_checkout_fields');
    function custom_override_checkout_fields($fields)
    {
    $fields['billing']['billing_company']['placeholder'] = 'Business Name';
    return $fields;
    }