I just created a custom Woocommerce 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_rate
right now.
Question:
How can I set the shipping method to custom_shipping
for users who meet a requirement, for the entirety of their session?
Tried:
$chosen_methods = $woocommerce->session->set('chosen_shipping_methods', array('purolator_shipping');
This sets the session variable 'chosen_shipping_methods' correctly 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.