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

Default Price and Price after currency switcher not working

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.

Hello,

I am using the WPCS plugin along with TablePress to display TLD prices. There are 650+ TLDs per tier(Tier 1, 2, 3, and Elite plan). I am importing sheets of each into TablePress, in which I have used the WPCS shortcode for the prices. I am using the WP Rocket plugin. The issue I am facing is that when I first load the page, all the prices are displayed correctly in INR, which is expected, as by default, I have set the price in INR. When I switch the currency to USD, price of some TLDs are displayed in USD but remain in INR, or vice versa. I have increased max_input_vars to 50000. I have cleared all cache. I have kept the currency storage setting as a cookie. Also, the setting of"I am using cache plugin setting" as YES. I have tried adding the prices page to Never Cache URLs in WP Rocket. After trying all of these, I am still facing the issue. Can you please let me know the issue and the correct, working solution to resolve it? It is affecting my sales. Please note that all the plugins are up to date. So please give me the solution. If you need anything else, let me know.

Regards,

 

Hello Snehal

Thank you for the detailed description, it made the cause easy to find.

This is an unusual case, we have not seen a page with so many prices before. When the option"I am using cache plugin on my site" is enabled, the plugin collects all prices on the page and asks the server to redraw them in the selected currency with one request. For safety the server processes at most 500 prices per request. Your page has several thousand prices (650+ TLDs in each of the 4 tiers), so only the first 500 are redrawn and the rest stay in the previous currency. That is why some prices switch to USD and some stay in INR. It also explains why max_input_vars, the cache exclusion and the storage setting did not change anything.

Let's try one experiment: the prices can be sent to the server in portions of 500. Please make a backup copy of the file first, then open via FTP or your hosting file manager:

wp-content/plugins/currency-switcher/js/front.js

Find this code (around line 175):

var data = {
    action:"wpcs_get_prices_html",
    prices_data: prices_data,
};
jQuery.post(wpcs_ajaxurl, data, function (data) {
and replace it with:
// The server redraws at most 500 prices per request, so send them in chunks
var wpcs_price_chunks = [];
for (var wpcs_ci = 0; wpcs_ci < prices_data.length; wpcs_ci += 500) {
    wpcs_price_chunks.push(prices_data.slice(wpcs_ci, wpcs_ci + 500));
}
if (!wpcs_price_chunks.length) {
    // keep one request even with no prices, it also syncs the switcher on cached pages
    wpcs_price_chunks.push([]);
}
jQuery.each(wpcs_price_chunks, function (wpcs_chunk_index, wpcs_chunk) {
var data = {
    action:"wpcs_get_prices_html",
    prices_data: wpcs_chunk,
};
jQuery.post(wpcs_ajaxurl, data, function (data) {
Then scroll down to the end of this jQuery.post block, it ends with the line:
});
right before the closing brackets of the"if (typeof wpcs_array_of_get.currency" condition. Add one more line directly after it:
});

This closes the new loop. Save the file, clear the WP Rocket cache (WP Rocket may minify or combine JavaScript, so the old version can stay in its cache) and then clear your browser cache or open the page in a private window.

After that please switch the currency to USD and back to INR a few times and let me know whether all prices on the page now switch correctly.

Best regards,
Alex

 

Hello,

Thanks for the support and the solution.

I have updated the code.

The price is getting update but now facing one issue.

When I switch the currency, the price updates correctly, but the currency doesn't switch.

For example, on the first load, the price displays in INR, which is expected by default. The button currency is INR.

On switching the currency to USD, prices are getting updated to USD for all TLDs, but the button currency is not changing. It remains in INR.

Can you please let me know the issue and a correct, working solution for the same?

If you need anything else, please let me know.

Regards,

Snehal J

 

 

Hello Snehal

Thank you for testing. All prices now switch, so the chunked requests work.

The button is a separate issue, and it would happen even on a page with few prices. With"I am using cache plugin on my site" enabled, the page comes from the cache with the switcher drawn in the currency the page was cached in, and the plugin is supposed to correct it after the AJAX price update. The switcher styles 1, 2 and 3 of the [wpcs] shortcode wait for a JavaScript event to update their button, but that event was never sent, so the button kept the cached currency while the prices changed. I fixed that, and I also changed the code so the switcher is redrawn once, after all price chunks have answered, instead of once per chunk.

The corrected file is attached in the private area of this ticket. Please replace:

wp-content/plugins/currency-switcher/js/front.js

with it. It already contains the chunked price update, so your previous manual change is not needed anymore. Fix will be included in to the next update.

After that, clear the WP Rocket cache (it may keep a minified or combined copy of the old JavaScript) and open the page in a private window. Please switch to USD and back to INR a few times and check both the prices and the button.

Best regards,
Alex

Hi,

Thanks for the support.

I updated the front.js file as suggested, but the issue isn't resolved.

The price is displaying correctly, but the button currency is not changing.

Kindly check and let me know the issue with correct solution.

Regards,

Snehal j

 

 

Hello,

Any update on this?

As the switcher is not working properly after making the changes as mentioned, kindly let me know the correct solution to make it work.

Please let me know if you need any other information.

Regards,

Snehal J

Hello Snehal

Thank you for checking.

The corrected front.js does update the button, so most likely your site still loads the old copy of the file. The plugin version stayed the same, so the script address did not change either, and WP Rocket, a CDN or the browser can keep serving the previous file.

Please do the following:

1. Upload the corrected front.js from the private area of this ticket again into wp-content/plugins/currency-switcher/js/, replacing the existing file.
2. Clear the WP Rocket cache. If you use Cloudflare or another CDN, purge it too.
3. Clear your browser cache, or open the page in a private window.
4. Switch the currency a few times and check the button.

Also, please send me the link to the page with the prices, so I can check it directly (you can use private area of this ticket).

Best regards, Alex

Hello,

I replaced the file again and cleared the cache, but the button still isn't working.

I shared the page link in a private area where the prices and the button are visible.

Kindly check and give me a solution ASAP, as it is affecting my sales.

Regards,

Snehal j

Hello Snehal

Thank you for the link, it let me check the page directly and find the cause.

The chunked price update was working correctly on your site. The switcher on your page is the designer drop-down, and it is drawn by a second script, js/sd/front.js. That file still took the currency from the cached copy of the page, so it kept showing the currency the page had been cached in, while the prices were already redrawn in the selected one. Replacing only js/front.js could not fix it, and that is why the button stayed the same after you uploaded the file.

Both fixes are now released in version 1.3.4 on wordpress.org:
- all prices on the page are redrawn after switching, even when there are thousands of them
- the switcher shows the selected currency on cached pages

WordPress usually shows the update within 24 hours. You can also go to Dashboard > Updates and press"Check again" to get it right away. If you prefer not to wait, you can download the plugin from wordpress.org and install it over the current one (Plugins > Add New > Upload Plugin, then"Replace current with uploaded"). Your settings will stay as they are.

After updating, please clear the WP Rocket cache, purge your CDN if you use one, and open the page in a private window. The version number has changed, so browsers will load the new scripts.

Please switch to USD and back to INR a few times and let me know how it works.

Best regards,
Alex

Hello,

Thank you so much for your support.

It is working fine now, but it is slow to load and very laggy.

Could you please check and provide a solution?

Regards,

Snehal j

 

Hello Snehal

Thank you for confirming, I am glad all prices and the switcher now work correctly.

The slowness comes from the size of the page itself. Your page has several thousand prices, and with"I am using cache plugin on my site" enabled, every price is redrawn in the visitor's currency through requests to the server after the page loads. With 2,600+ prices that means 6 requests to the server and thousands of replacements in the browser on every visit, which is what you see as lag.

Here are the options:

1. Split the prices into separate pages, one per tier (Tier 1, Tier 2, Tier 3, Elite). Each page would then have around 650 prices instead of 2,600, so the redraw needs about 4 times less work.

2. Check your hosting resources. The price requests run in parallel, and on hosting with a small number of PHP workers they wait in a queue, which adds seconds. A plan with more PHP workers makes them finish faster.

3. If no other pages of your site are cached by WP Rocket (you mentioned the prices page is already excluded), you can switch"I am using cache plugin on my site" off. Then prices are rendered by the server directly in the selected currency and no redraw happens at all. If other pages are cached, keep this option on.

4. I prepared a small add-on just for your prices page, it is attached in the private area of this ticket (wpcs-prices-page-no-redraw.php). On that page only, it makes sure the page is never served from cache and turns off the redraw, so the server renders all prices once, directly in the selected currency. All other pages keep working as they do now. To install it, upload the file to wp-content/mu-plugins/ (create the mu-plugins folder if it does not exist). There is nothing to activate, it works as soon as the file is there. To remove it, just delete the file.

If your prices page has an address other than /domain-prices/, please tell me and I will adjust the file.

After installing, clear the WP Rocket cache, open the page in a private window and switch between INR and USD a few times.

Best regards,
Alex

Hello,

I tried adding an add-on file to wp-content/mu-plugins/, but it is still not working. When I add it, it uses the previous price (i.e., USD).

I have https://www.connectreseller.com/domain-prices/ as the main page, in which I have created tabs and am fetching tier1, tier2, and tier3 templates.

"I am using a cache plugin" is enabled in the WPCS plugin, and the price page is not added to"Never cache URLs" in the WP Rocket plugin.

Please help me to resolve this issue. If possible, please help to resolve this today only, as there will be 3 days of holidays.

Awaiting your response.

If you need anything else from my end, let me know.

Regards,

Snehal

Hello Snehal

Thank you for the details.

The add-on could not work in your setup, because the prices page is not excluded from the WP Rocket cache. WP Rocket serves a cached copy of the page before the add-on is even loaded, and since the add-on turns off the redraw on that page, the currency of the cached copy stays on the screen. That is why you see the previous currency.

Please try this first:

1. In WP Rocket go to Advanced Rules and add /domain-prices/ to"Never Cache URL(s)".
2. Clear the WP Rocket cache, and purge your CDN too if you use one.
3. Open the page in a private window and switch between INR and USD a few times.

Please also tell me how the tabs work: are all three tier templates already in the page when it opens, or is each tier loaded only when its tab is clicked? If they are loaded on click, those requests go to a different address and the add-on does not cover them.

Another option is still to split the prices into separate pages, one per tier. I cannot promise it removes the lag completely, but each page will have about 4 times fewer prices to process.

If none of this is enough, your page needs a custom solution rather than the standard redraw. The idea is that the page loads all prices in the selected currency with a single request, then a small script places them into the table in the browser, and the same script watches the page and updates any prices that appear later, for example when a tab is opened. This needs experiments on a real copy of your site, otherwise we will keep going back and forth in messages. For that please create a staging site, a full copy of your live site, and put WP admin and FTP access to it in the private area of this ticket.

https://share.pluginus.net/image/i20230222134241.png
https://share.pluginus.net/image/i20230222134615.png

It would also help a lot if you record a short screen video showing the problem as it happens on your side: open the page, switch the currency, open the tabs, and let the video run until the prices finish updating. Seeing which prices update late, in what order, and how long it takes will let me find the pattern much faster.

Best regards,
Alex