1
votes

I am having post code based minimum order amount for orders for my Woocommerce shop. Also I am having postcode based custom error messages to appear once the user type postcode like how much he needs more to checkout. So preventing the user to type invalid postcodes(which means the postcodes that we do not deliver), i am displaying drop down to pick his valid postcode in Checkout page.

Based on this thread Change postcode shipping field to a dropdown in Woocommerce, i could turn the postcode field to dropdown with the options.

But i am getting the error that the "Postcode is not valid" by Woocommerce when i select any option from the drop down. Also my custom messages also not displaying.

Below is the code I m using from the above thread.

add_filter( 'woocommerce_default_address_fields' , 'customize_postcode_fields' );
function customize_postcode_fields( $adresses_fields ) {

$adresses_fields['postcode']['type'] = 'select';
$adresses_fields['postcode']['options'] = array(
'' => __('Select your postcode', 'woocommerce'),
'option_1' => '000001',
'option_2' => '000002',
'option_3' => '000003'
);

return $adresses_fields;

}
1

1 Answers

1
votes

Try to use the following instead:

add_filter( 'woocommerce_default_address_fields' , 'customize_postcode_fields' );
function customize_postcode_fields( $adresses_fields ) {
    $adresses_fields['postcode']['type'] = 'select';
    $adresses_fields['postcode']['input_class'] = array('state_select');
    $adresses_fields['postcode']['options'] = array(
        '' => __('Select your postcode', 'woocommerce'),
        '000001' => '000001',
        '000002' => '000002',
        '000003' => '000003'
    );

    return $adresses_fields;
}

Code goes in functions.php file of your active child theme (or active theme). Tested and works on last WooCommerce version 4.5.1 under Storefront theme.