• Resolved kugavosuca

    (@kugavosuca)


    I am trying to force shipping estimate to use postcode and country. Only country seems to be required by default, and postcode is optional with the field even greyed. Here is an example image of Change Address fields. How do I require both country and postcode? Note – State and city are not required for my use case.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Support Hannah S.L.

    (@fernashes)

    Automattic Happiness Engineer

    Hey there,

    I’m not sure how you’d make the postcode field on the cart’s shipping form required – I’ll leave this thread open for a bit to see if anyone else can chime in.

    Thread Starter kugavosuca

    (@kugavosuca)

    Hi Hannah. I am a little surprised that postcode isn’t required by default. If you try to write a custom shipping method against any of the major carriers, they require postcode. For example, USPS domestic method requires “ZipDestination”. I realize that postcode can be set to required on checkout. But, I’d like to avoid having the estimate much different than the actual checkout quote.

    The ideal solution is to require postcode in the cart for shipping estimate. If that is impossible, are either of these two options possible:
    1. Not display a shipping method in the cart until a postcode and country are populate. Display message to populate the fields if empty.
    2. Disable shipping estimator in the cart – not ideal option at all.

    Thanks.

    Plugin Support Hannah S.L.

    (@fernashes)

    Automattic Happiness Engineer

    Hey there,

    Postcode isn’t required by default as each shipping provider decides how they want to handle shipping.

    If you feel this should be added to WooCommerce, you’re welcome to add it to our Ideas Board – others can then vote on the ideas, and we use it to track all requests. You can find it here: http://ideas.woocommerce.com/forums/133476-woocommerce

    Thread Starter kugavosuca

    (@kugavosuca)

    Hi Hannah,

    I think there is some confusion around what I am asking and so this thread is not actually “Resolved”.

    I understand postcode is not required by default, hence the purpose of my question asking how I can do so. I don’t think it needs to be required by default and as such, an idea doesn’t need to be submitted to the Ideas Board.

    To clarify, I am asking if I can customize only my instance of WooCommerce to make postcode required? Should I resubmit this question since this thread is incorrectly marked as Resolved?

    Thanks.

    Plugin Support Hannah S.L.

    (@fernashes)

    Automattic Happiness Engineer

    Hey there,

    As mentioned, we do try to mark threads as resolved to keep the forums clean. That doesn’t in any way lock down the thread.

    To clarify, I am asking if I can customize only my instance of WooCommerce to make postcode required? Should I resubmit this question since this thread is incorrectly marked as Resolved?

    I don’t know how to do this – I wasn’t able to find any information on it while searching. I’m going to leave it open for a bit to see if anyone is able to chime in to help you out.

    I can also recommend the following places for more development-oriented questions:

    1. WooCommerce Slack Community: https://woocommerce.com/community-slack/
    2. Advanced WooCommerce group on Facebook: https://www.facebook.com/groups/advanced.woocommerce/
    Thread Starter kugavosuca

    (@kugavosuca)

    Thanks for the other links. I would argue that marking a thread as “Resolved” on behalf of the OP when it is actually not, is misleading to potential other responders and greatly diminishes the chances of actually getting a real resolution. Well, I’ll try elsewhere since my efforts here are being squashed.

    To anyone else that ever comes across this thread, I’ll add my findings so far. This applies to wordpress 4.9.8, woocommerce 3.4.4

    I haven’t found a way to require postcode, but have found a way to suppress shipping calculations until a postcode is entered. This is not a elegant. – In woocommerce/templates/cart/cart-shipping.php customize it to check if $package[‘destination’][‘postcode’] is empty. If it is, display a message to populate it (along with any other fields you require). Set $available_methods to false. Next adjust the CSS of the postcode input field so that it is not greyed out and matches the look of the other fields. You can also tweak Shipping settings to ‘Hide shipping costs until address is entered’. This is high level, but should get you started if no other resolution is found.

    Plugin Support Ryan Ray

    (@ryanr14)

    Hi there,

    To make the post code field required on the cart page calculator I think the best option is to copy the template file into your theme.

    See our doc on template files first. Then you’ll want to copy the file from woocommerce/templates/cart/shipping-calculator.php into your theme.

    The important part will then be to modify the postcode form starting on line 80 to add the required tag. Right after <input type=”text” you can add required before class=”input-text”.

    It ends up looking like this.

    Link to image: http://cld.wthms.co/EHobEE

    This won’t add an asterisk next to the field, which will require some CSS modifications or anything you prefer to notate the field as required. Otherwise it won’t let a customer submit the shipping calculator forms.


    Link to image: http://cld.wthms.co/CRnzYu

    • This reply was modified 7 years, 6 months ago by Ryan Ray.
    jessepearson

    (@jessepearson)

    Automattic Happiness Engineer

    We haven’t heard back from you in a while, so I’m going to mark this as resolved – if you have any further questions, you can start a new thread.

Viewing 8 replies - 1 through 8 (of 8 total)

The topic ‘Require postcode for shipping calculation’ is closed to new replies.