Title: Problem with chosen_shipping_methods
Last modified: February 17, 2017

---

# Problem with chosen_shipping_methods

 *  [Web Expert](https://wordpress.org/support/users/seldimi/)
 * (@seldimi)
 * [9 years, 5 months ago](https://wordpress.org/support/topic/problem-with-chosen_shipping_methods/)
 * Hello.
    I have been using command $woocommerce->session->get( ‘chosen_shipping_methods’)
   to detect the chosen shippinh way to unset some payment gateways
 * The code found on web was
 *     ```
       function my_custom_available_payment_gateways( $gateways ) {
           global $woocommerce;
       	$chosen_shipping_rates = $woocommerce->session->get( 'chosen_shipping_methods' );
       	// When 'local delivery' has been chosen as shipping rate
       	if ( in_array( 'local_delivery', $chosen_shipping_rates ) ) {
       		// Remove bank transfer payment gateway
       		unset( $gateways['cod'] );
           }elseif (in_array( 'flat_rate', $chosen_shipping_rates ) || in_array( 'flat_rate:1', $chosen_shipping_rates)){
               unset( $gateways['cp'] );
       	}
       	return $gateways;
       }
       */
       add_filter( 'woocommerce_available_payment_gateways', 'my_custom_available_payment_gateways' );
       ```
   
 * The problem is that code works fine, but on wp-admin (on another plugin though)
   it breaks the code and says falat error on my functions.php file where that call
   is made. (and post.php returns 500). Is there any alternative way to get the 
   user selected shipping methold? Or should I call filter somewher else? Or there
   is another snippet that does hide some payment methods if user picks one shipping?

The topic ‘Problem with chosen_shipping_methods’ 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

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

 * 0 replies
 * 1 participant
 * Last reply from: [Web Expert](https://wordpress.org/support/users/seldimi/)
 * Last activity: [9 years, 5 months ago](https://wordpress.org/support/topic/problem-with-chosen_shipping_methods/)
 * Status: not resolved