Created
December 20, 2017 18:32
-
-
Save mohsinrasool/7a001f68249871e290b234cffc5e69d2 to your computer and use it in GitHub Desktop.
Fixing get_country() on null for woocommerce-gateways-country-limiter by WPML
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
// Change filter_country function to following | |
function filter_by_country($payment_gateways){ | |
$woocommerce = function_exists('WC') ? WC() : $GLOBALS['woocommerce']; | |
if($woocommerce == null || $woocommerce->customer == null ) | |
return $payment_gateways; | |
$customer_country = $woocommerce->customer->get_country(); | |
foreach($payment_gateways as $gateway_id => $gateway){ | |
if( | |
$this->settings[$gateway_id]['option'] == 'all_except' && in_array($customer_country, $this->settings[$gateway_id]['countries']) || | |
$this->settings[$gateway_id]['option'] == 'selected' && !in_array($customer_country, $this->settings[$gateway_id]['countries']) | |
){ | |
unset($payment_gateways[$gateway_id]); | |
} | |
} | |
return $payment_gateways; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment