<?php //Disable Payment Gateway For Specific Shipping Method add_filter( 'woocommerce_available_payment_gateways', 'wpflames_gateway_disable_shipping_368' ); function wpflames_gateway_disable_shipping_368( $available_gateways ) { global $woocommerce; if ( !is_admin() ) { $chosen_methods = WC()-&gt;session-&gt;get( 'chosen_shipping_methods' ); $chosen_shipping = $chosen_methods[0]; //Free shipping if ( isset( $available_gateways['cod'] ) && 0 === strpos( $chosen_shipping, 'free_shipping' ) ) { unset( $available_gateways['cod'] ); } //Flat rate if ( isset( $available_gateways['cod'] ) && 0 === strpos( $chosen_shipping, 'flat_rate' ) ) { unset( $available_gateways['cheque'] ); } //Local pickup if ( isset( $available_gateways['cod'] ) && 0 === strpos( $chosen_shipping, 'local_pickup' ) ) { unset( $available_gateways['cod'] ); } //Cheque if ( isset( $available_gateways['cod'] ) && 0 === strpos( $chosen_shipping, 'flat_rate:2' ) ) { unset( $available_gateways['cheque'] ); } } return $available_gateways; }
Leave a Reply