WooCommerce Currency Switcher, by PluginUs.NET
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
add_action('wpo_before_update_cart', function ($cart_data) { if ( ! class_exists('WOOCS') ) { return; } global $WOOCS; $location = wc_get_customer_default_location(); $country_code = $location['country']; if (isset($cart_data['customer']['billing_country']) && $cart_data['customer']['billing_country']) { $country_code = $cart_data['customer']['billing_country']; } if (isset($cart_data['customer']['shipping_country']) && $cart_data['customer']['shipping_country']) { $country_code = $cart_data['customer']['shipping_country']; } $WOOCS->set_currency($WOOCS->get_currency_by_country($country_code)); }); |