PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Currency for single product page [price] lazy loaded

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

Hi,

 

I'm using Seraphinite Accelerator cache and using Geolaction of woocommerce plus have cache turned on under options.

I find currency drop down loads just fine in top right of my site, but the [price] field has spinning Ajax as I suspect its being lazy loaded by accelerator.
When user moves mouse or interacts with site, then price shows.

What script or element or how can I tell accelerator to not lazy load price field so it shows immediately.
I have tried enabling preload Ajax prices.
I have tried setting to Redis DB but then often get errors on page load.

Help please

Hello

It looks like your optimization is set to load js scripts after the first user event.

You can disable the loading animation - https://share.pluginus.net/image/i20241206103737.png

OR you can disable ajax loading of prices - https://share.pluginus.net/image/i20241206104046.png

I came up with the following code snippet if anyone is using cloudflare and currency isn't working...

add_filter('woocommerce_geolocation_country_code', function ($country) {
if (!empty($_SERVER['HTTP_CF_IPCOUNTRY'])) {
return sanitize_text_field($_SERVER['HTTP_CF_IPCOUNTRY']);
}
return $country;
});

I have geolocation set for store (not geolocation for cache as that always broke the site).

The code snippet will hard set currency to users location as cloudflare always serves from the closest node. this method is much more accurate than any IP databases.

Only thing I have to work out now is how to maybe set that with a cookie or something and then allow user to select to change currency.

Thought I would share so perhaps WOOCS/FOX could implement code for it to make it easier for others using cloudflare

You can make a shortcode to test

// Shortcode for Debug
function debug_geolocation_shortcode() {
$cf_country = !empty($_SERVER['HTTP_CF_IPCOUNTRY']) ? sanitize_text_field($_SERVER['HTTP_CF_IPCOUNTRY']) : 'Not detected';
$user_ip = !empty($_SERVER['REMOTE_ADDR']) ? sanitize_text_field($_SERVER['REMOTE_ADDR']) : 'Unknown IP';

$output ="<div>";
$output .="<strong>Geolocation Debug:</strong><br>";
$output .="CF-IPCountry:" . $cf_country ."<br>";
$output .="User IP:" . $user_ip ."<br>";
$output .="</div>";

return $output;
}

add_shortcode('geolocation_debug', 'debug_geolocation_shortcode');

in addition to above, I changed from Redis back to FOX session which fixed the drop-down with currency.

So above seems to be a viable solution for those using cloudflare :)

Great!  Thank you for your cooperation!

sorry after some testing I noticed that the repaint still has an issue until cloudflare cache the page... if I refresh page then it shows correct currency.

Does it have to repaint/javascript change the prices  or is there an option to do it server side?

That's the whole point of caching. The server sends the cached page without the server actually doing any work (generating the page).

sorry I mean when the cache expires at cloudflare and they need to refresh the cache, when the user that initiates that new cache, they land on a page and the prices dont repaint for some time from javascript

I dont know which one of your javascript files or calls need to be set to happen immediately, i.e. that the cache/accelerators do not delay your script.

I find that the if I dont move my mouse at all, the page never fully loads with lazy loaded javascript so we always see base currency, until an event which triggers the repaint

 

rather than doing the price rendering using javascript, we replace at php server side? so if HTTP_CF_IPCOUNTRY == nz then NZD.

possible ?

Hello

file - wp-content\plugins\woocommerce-currency-switcher\js\front.js

rather than doing the price rendering using javascript, we replace at php server side?  - Unfortunately, I don't understand what you mean.

I mean not paint with javascript the new price, just display the users currency price from the start, like making the store or product page echo the $price rather than it be client side javascript required

Ok!  Just  disable  this  option - https://share.pluginus.net/image/i20241209134232.png

Our plugin converts the price to the required currency on the server side. JS redraws prices only if they are cached