I would like to make a dropdown field when somebody tries to type post code in the shipping calculator, at cart page, so he can choose the field, rather than type it.
I have managed to make it at the checkout field, looking at how other people did it at StackOverflow.
This is the code I have put in function.php and it works at checkout:
add_filter( 'woocommerce_default_address_fields' , 'custom_override_default_postcode_field' );
function custom_override_default_postcode_field( $address_fields ) {
// Your postcodes array
$postcode_array = array(
'70101' => "70101",
'70202' => "70202",
'70220' => "70220",
'70223' => "70223",
'89245' => "89245",
'89247' => "89247"
);
$address_fields['postcode']['type'] = 'select';
$address_fields['postcode']['options'] = $postcode_array;
return $address_fields;
}
Then I have put shipping-calculator.php in my theme woocommerce cart php file and I can not figure out how to make a dropdown field at Cart.
This is the code for typing in postcode from woocommerce an shipping-calculator.php:
<?php if ( apply_filters( 'woocommerce_shipping_calculator_enable_postcode', true ) ) : ?>
<p class="form-row form-row-wide" id="calc_shipping_postcode_field">
<input type="text" class="input-text" value="<?php echo esc_attr( WC()->customer->get_shipping_postcode() ); ?>" placeholder="<?php esc_attr_e( 'Postcode / ZIP', 'woocommerce' ); ?>" name="calc_shipping_postcode" id="calc_shipping_postcode" />
</p>
<?php endif; ?>
How do I make it to be a dropdown, please?