I am building a food ordering website using Wordpress and Woocommerce. So far I have been doing good but got stuck at one point where the Shipping method should be chosen automatically.
What is the flow like? The user visits my websites and enters the zip code of delivery address and then my website shows the restaurants which deliver in that zip code. Some restaurants deliver in that zip code in less time and less shipping charges but some take more time and take more shipping charges.
What I have done so far is that I fetch the shipping codes from the database any restaurant delivers to. If the user's zip code doesn't exist in the list we alert else we move forward.
Next step is to fetch all the restaurants that deliver in that zip code in less delivery time and then restaurants that deliver in that zip code in more delivery time. Based on less or more delivery time I mark the user in Zone A or Zone B respectively.
I have flat rate shipping methods created for Zone A and Zone B which can be selected from the drop down in the Cart/Checkout Page. Now here it what the trouble is.
The user shouldn't select what the shipping rate would be. It should be automatically selected and applied based on what Zone the user has been marked into.
This automatic updating is not what I am able to achieve.
What I have tried?
The right process should be to put this Zone into Woocommerce session and it should be picked automatically and applied when the user reaches the cart or checkout page.
I am not able to find the right method to call which could trigger the ajax call to update shipping. Any ideas would be helpful.
Regards