• 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.