Quote from sametgs70 on September 18, 2024, 10:36
Hello,
Im trying to set up a currency switcher on a site im working on, i have a region switcher, custom coded into the site, that is changing the billing region in the cookie and its excluded from caching, Now i need the currency to also be based on the billing location, but this doesnt seem to be working..
I already saved the custom function as mentioned in your instructions, however, even though i changed the region on the frontend, i disabled wp-rocket, i checked all settings multiple times, the currency does not change when i cahnge the billing location.
The function i have:
// Override WOOCS country based on billing country and force currency change
add_action('woocommerce_customer_save_address', function($user_id, $load_address) {
global $WOOCS;
// Get billing country from WooCommerce
$billing_country = WC()->customer->get_billing_country();
if (!empty($billing_country)) {
// Set WOOCS to use billing country instead of GeoIP
$WOOCS->storage->set_val('woocs_user_country', $billing_country);
// Get and set currency based on billing country
$_currency = $WOOCS->get_currency_by_country($billing_country);
if ($_currency) {
$WOOCS->set_currency($_currency);
WC()->session->set('woocs_current_currency', $_currency); // Update session with new currency
}
}
}, 10, 2);
I hope you guys can help me out..
Hello,
Im trying to set up a currency switcher on a site im working on, i have a region switcher, custom coded into the site, that is changing the billing region in the cookie and its excluded from caching, Now i need the currency to also be based on the billing location, but this doesnt seem to be working..
I already saved the custom function as mentioned in your instructions, however, even though i changed the region on the frontend, i disabled wp-rocket, i checked all settings multiple times, the currency does not change when i cahnge the billing location.
The function i have:
// Override WOOCS country based on billing country and force currency change
add_action('woocommerce_customer_save_address', function($user_id, $load_address) {
global $WOOCS;
// Get billing country from WooCommerce
$billing_country = WC()->customer->get_billing_country();
if (!empty($billing_country)) {
// Set WOOCS to use billing country instead of GeoIP
$WOOCS->storage->set_val('woocs_user_country', $billing_country);
// Get and set currency based on billing country
$_currency = $WOOCS->get_currency_by_country($billing_country);
if ($_currency) {
$WOOCS->set_currency($_currency);
WC()->session->set('woocs_current_currency', $_currency); // Update session with new currency
}
}
}, 10, 2);
I hope you guys can help me out..