Set shipping method programmatically
-
I just created a custom shipping method with the id of
custom_shipping. The option now appears on the Woocommerce -> Settings -> Shipping admin page.I would like to set the shipping method dynamically based on a user’s credentials. The default method is
flat_rateright now.Question: How can I set the shipping method to
custom_shippingfor users who meet a requirement, for the entirety of their session?Tried:
$woocommerce->session->set('chosen_shipping_methods', array('purolator_shipping');This sets the session variable
chosen_shipping_methodscorrectly on my cart page, but upon moving to checkout, the session goes back to using the flat_rate shipping method.There must be a hook or filter that I can plug into to change the shipping method upon cart-session creation or something. (When a user adds something to cart for first time).
I would ideally like to set the new shipping method before anything else is loaded so the shipping method looks correct on their cart and checkout summaries.
Guidance appreciated.
The topic ‘Set shipping method programmatically’ is closed to new replies.