Created
December 25, 2014 18:27
-
-
Save anunay/830085a20ac80bff6485 to your computer and use it in GitHub Desktop.
Hide paypal based on shipping methods - Woocommerce
This file contains 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
<?php | |
function alter_shipping_methods($available_gateways){ | |
global $woocommerce; | |
$chosen_titles = array(); | |
$available_methods = $woocommerce->shipping->get_packages(); | |
$chosen_rates = ( isset( $woocommerce->session ) ) ? $woocommerce->session->get( 'chosen_shipping_methods' ) : array(); | |
foreach ($available_methods as $method) | |
foreach ($chosen_rates as $chosen) { | |
if( isset( $method['rates'][$chosen] ) ) $chosen_titles[] = $method['rates'][ $chosen ]->label; | |
} | |
if( in_array( 'First-Class Mail® (USPS)', $chosen_titles ) ) { | |
unset($available_gateways['paypal']); | |
} | |
return $available_gateways; | |
} | |
add_action('woocommerce_available_payment_gateways', 'alter_shipping_methods'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment