Last active
February 19, 2018 20:43
-
-
Save bolderelements/c814dc8ddca1fbb9aa2a85b914bcba6d to your computer and use it in GitHub Desktop.
Hide Payment Gateway Based on Shipping Option Selected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Hide the PayPal payment option when the customer selects a specific Table Rate option | |
* Code snippets should be added to the functions.php file of your child theme | |
* | |
* @return array | |
*/ | |
function alter_payment_gateways( $list ){ | |
// Retrieve chosen shipping options from all possible packages | |
$chosen_rates = ( isset( WC()->session ) ) ? WC()->session->get( 'chosen_shipping_methods' ) : array(); | |
if( in_array( 'betrs_shipping:2-3', $chosen_rates ) ) { | |
$array_diff = array('WC_Gateway_Paypal'); | |
$list = array_diff( $list, $array_diff ); | |
} | |
return $list; | |
} | |
add_action('woocommerce_payment_gateways', 'alter_payment_gateways'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment