Undefined index on a site with multiple currencies
-
Notice: Undefined index: NGN
plugins/woocommerce-gateway-affirm/includes/class-wc-gateway-affirm.php in WC_Gateway_Affirm::get_country_by_currency at line 2314Our page has multiple currencies. When order is edited above mentioned notice is logged.
It is assumed in the code only two currencies are supported, there’s no sanity check for anything else but USD and CAD.Function code:
public function get_country_by_currency( $currency_code ) {
$c_map = array(
'USD' => array( 'US', 'USA' ),
'CAD' => array( 'CA', 'CAN' ),
);
return $c_map[ $currency_code ];
}This leads to one more notice:
PHP Notice: Trying to access array offset on value of type null in /plugins/woocommerce-gateway-affirm/class-woocommerce-gateway-affirm.php on line 1544
Fixing
get_country_by_currency()
is helps further from occurring.Temp patch I applied:
- return $c_map[ $currency_code ];
+ return $c_map[ $currency_code ] ?? [ '', '' ];
- You must be logged in to reply to this topic.