• Resolved codythub

    (@codythub)


    Hi woocommerce,

    I was recently working on shipping methods in woocommerce that allows customers to pay for a specific shipping fee based on their location. But, during checkout when the country is selected, post/zip code field disappears. Went ahead to choose a different country and the post/zip code field appears.

    please, I’ll like to display zip code options during checkout, how do I get this done?
    I’m so confused.
    Thank you.

Viewing 15 replies - 1 through 15 (of 19 total)
  • Zach W

    (@dynamiczach)

    Automattic Happiness Engineer

    Howdy @codythub!

    I was recently working on shipping methods in woocommerce that allows customers to pay for a specific shipping fee based on their location.

    Were you using default WooCommerce functionality for this, or another shipping plugin?

    during checkout when the country is selected, post/zip code field disappears. Went ahead to choose a different country and the post/zip code field appears.

    Is the zip code not displaying for specific countries? If not, can you list the countries this is a problem for? Thanks!

    Thread Starter codythub

    (@codythub)

    Hello Zack,

    Thank you for your response.
    To your first question yes, I’m using a default WooCommerce functionality.
    The zip code field doesn’t display for specific countries. In this case- Nigeria.

    Zach W

    (@dynamiczach)

    Automattic Happiness Engineer

    Howdy!

    Thanks for the explanation!

    The zipcode/postcode field is removed for specific countries, Nigeria included.

    You can read more about the reasoning here:

    https://github.com/woocommerce/woocommerce/issues/21055

    If you’d like to comment on that link, please feel free. ??

    Thread Starter codythub

    (@codythub)

    Thanks once again Zach.

    I’ve visited the link.
    However, can you please suggest another possible way to solve this problem of paying for shipping items based on their location?

    Actually, I can input different states and fixed rates for them individually. But what can you suggest adding different locations(in that state). Woocommerce only brings up states and not areas within the state.

    Sorry for the inconvenience.

    Zach W

    (@dynamiczach)

    Automattic Happiness Engineer

    Howdy!

    You can make the postcode fields visible and compulsory via custom code.

    We have some docs here – https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/#section-2

    The last snippet in that section shows how to make a field optional, changing false to true would make it compulsory.

    To make it visible, the same code, but instead of ['required'] you would use ['hidden'] and set that to false.

    Or you could look at something like this to break states down to constituent cities and municipalities – https://www.ads-software.com/plugins/states-cities-and-places-for-woocommerce/ instead.

    I hope this helps!

    Thread Starter codythub

    (@codythub)

    Hi again Zach!

    Thank for taking time to respond to my messages.

    I have to be totally honest with you, I don’t have much knowledge of Php(this is in response to the first link sent).

    However, I installed the plugin in the second link and could see the constitutent cities in the state.

    My question now is, how can I add individual shipping flatrates for these municipalities on woocommerce settings via shipping zones. I’ve tried to add them but I can only get past the state(but doesn’t show the municipalities when typed)

    I apologize for the inconvenience once more.

    Thanks.

    Zach W

    (@dynamiczach)

    Automattic Happiness Engineer

    Howdy @codythub!

    You’d need to do some custom development to get the cities, etc. added as shipping options within the Shipping Zones, as there isn’t an easy way to do that currently within WooCommerce itself.

    I don’t have that code available off hand, so it would need to be developed.

    There is an Advanced WooCommerce Facebook Group here: https://www.facebook.com/groups/advanced.woocommerce/ and a WooCommerce Slack Community here: https://woocommerceslack.herokuapp.com/ and someone in one of those may be able to help, I’d start there. ??

    Otherwise, you may need to look into have someone custom-develop something like that.

    Thread Starter codythub

    (@codythub)

    Thank you for your help.
    Really do appreciate!

    Hi there!

    ZACH, can you kindly help us and provide the function (to add to the functions.php) to override the HIDE postal code and make it always visible?

    Thanks!

    • This reply was modified 5 years, 9 months ago by goosept.

    tried this…

    Didn’t worked!

    // Hook in
    add_filter( ‘woocommerce_default_address_fields’ , ‘custom_override_default_address_fields’ );

    // Our hooked in function – $address_fields is passed via the filter!
    function custom_override_default_address_fields( $address_fields ) {
    $address_fields[‘postcode’][‘hidden’] = false;

    return $address_fields;
    }

    Hi,
    and thank you

    For MZ (Mozambique) don’t need de postalcode to.

    How can i make this hook to disapear the postal code field, when i choose Mozambique country?

    • This reply was modified 5 years, 6 months ago by sotnas.
    • This reply was modified 5 years, 6 months ago by sotnas.
    Stef

    (@serafinnyc)

    I’m going to comment here as I did for @sotnas in his own thread so that others can maybe learn from this. I would advise you simply make the field optional. By doing this you avoid getting specific.

    As always, add this to your child theme and never to a parent theme.

    add_filter( 'woocommerce_default_address_fields', 'ssd_postcode_fields' );
    function ssd_postcode_fields( $address_fields ) {
        $address_fields['postcode']['required'] = false;
    
        return $address_fields;
    }

    Any issues let me know.

    Stef,

    thank you

    but these code, only make postcode not required… don’t unset our hide…
    Shure?

    I have these pece.

    But don’t work to.

    
    add_filter( 'woocommerce_default_address_fields', 'remove_billing_postcode_aomz', 10, 1 );
    
    function remove_billing_postcode_aomz ($address_fields){
        global $woocommerce;
        $country = $woocommerce->customer->get_billing_country();
        	if( $country !== 'AO' or MZ' ){
        		unset($address_fields['billing']['billing_postcode']);
        	}
        return $address_fields;
    }
    
    Stef

    (@serafinnyc)

    Like I said, this is the easiest way to do this. If you want you can always hire a developer to customize it your way. What you’re asking requires customization.

    You can find a qualified developer here.
    https://woocommerce.com/customizations

    • This reply was modified 5 years, 6 months ago by Stef.
Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Post/zip code doesn’t show during checkout when i select my country’ is closed to new replies.