Support » Plugin: WooCommerce » Prefilled Checkout Fields – Postcode not working

  • Resolved Eini0815

    (@eini0815)


    Hello,

    I have managed to prefill some checkoutfields like City or adress_1 – but the postcode is not prefilled with the same syntax:

    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    
    function custom_override_checkout_fields( $fields ) {
         $fields['billing']['billing_address_1']['default'] = 'Street';
    	 $fields['billing']['billing_city']['default'] = 'City';
    	 $fields['billing']['billing_postcode']['default'] = '12345';
         return $fields;

    Also tried to apply this with the woocommerce_default_address_fields filter in addition:

    add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_address_fields' );
    
    function custom_override_default_address_fields( $address_fields ) {
         $address_fields['address_1']['default'] = 'Street';
    	 $address_fields['city']['default'] = 'City';
    	 $address_fields['postcode']['default'] = '12345';
         return $address_fields;
    }

    But only Postcode is not prefilled.

    Regards Franz

    https://wordpress.org/plugins/woocommerce/

Viewing 3 replies - 1 through 3 (of 3 total)
  • This add_filter function works for me:

    function custom_override_default_address_fields( $address_fields ) {
      $address_fields['address_1']['placeholder'] = 'Street';
      $address_fields['city']['placeholder'] = 'City';
      $address_fields['postcode']['placeholder'] = '12345';
      return $address_fields;
    }

    Thread Starter Eini0815

    (@eini0815)

    With this you only get a placeholder – not a prefilled field (so a customer has to re enter the value).

    The placeholder value also works – so I have the correct fields and syntax – but not the default value.

    Thread Starter Eini0815

    (@eini0815)

    Hi,

    just for information – solved it with a trick:

    add_filter( 'woocommerce_checkout_fields' , 'custom_override_checkout_fields' );
    function custom_override_checkout_fields( $fields ) {
     $fields['billing']['billing_postcode'] = array(              //replace billing_postcode with your custom field name or something ;)
             'label' => __('Postcode', 'woocommerce'),              //replace Postcode with the field label
              'placeholder' => _x('Postcode', 'placeholder', 'woocommerce'),         //replace Postcode with your custom default value
              'required' => false,
              'clear' => false,
              'type' => 'select',
              'class' => array('form-row-wide'),
              'options' => array(
                       'option_a' => __('123456', 'woocommerce' ),
              )
     );
    return $fields;
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Prefilled Checkout Fields – Postcode not working’ is closed to new replies.