Skip to content

Instantly share code, notes, and snippets.

@mohsinrasool
Created December 20, 2017 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohsinrasool/7a001f68249871e290b234cffc5e69d2 to your computer and use it in GitHub Desktop.
Save mohsinrasool/7a001f68249871e290b234cffc5e69d2 to your computer and use it in GitHub Desktop.
Fixing get_country() on null for woocommerce-gateways-country-limiter by WPML
// 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