Skip to content

Instantly share code, notes, and snippets.

@bolderelements
Last active February 19, 2018 20:43
Show Gist options
  • Save bolderelements/c814dc8ddca1fbb9aa2a85b914bcba6d to your computer and use it in GitHub Desktop.
Save bolderelements/c814dc8ddca1fbb9aa2a85b914bcba6d to your computer and use it in GitHub Desktop.
Hide Payment Gateway Based on Shipping Option Selected
/**
* 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