Title: Set shipping method programmatically
Last modified: August 30, 2016

---

# Set shipping method programmatically

 *  Resolved [amarie](https://wordpress.org/support/users/tuesdave/)
 * (@tuesdave)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/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_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:**
    `$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.
 * [https://wordpress.org/plugins/woocommerce/](https://wordpress.org/plugins/woocommerce/)

Viewing 1 replies (of 1 total)

 *  Plugin Contributor [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * (@mikejolley)
 * [10 years, 9 months ago](https://wordpress.org/support/topic/set-shipping-method-programmatically/#post-6534070)
 * If you want to force that method, you could do something similar to this and 
   remove the other methods if they have access to the special one [http://docs.woothemes.com/document/hide-other-shipping-methods-when-free-shipping-is-available/](http://docs.woothemes.com/document/hide-other-shipping-methods-when-free-shipping-is-available/)

Viewing 1 replies (of 1 total)

The topic ‘Set shipping method programmatically’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)
 * [shipping](https://wordpress.org/support/topic-tag/shipping/)

 * 1 reply
 * 2 participants
 * Last reply from: [Mike Jolley](https://wordpress.org/support/users/mikejolley/)
 * Last activity: [10 years, 9 months ago](https://wordpress.org/support/topic/set-shipping-method-programmatically/#post-6534070)
 * Status: resolved