Bunny CDN and Cloudflare
A CDN (content delivery network) serves cached copies of your pages from servers near your visitors, so your store loads fast everywhere. Bunny CDN and Cloudflare are two popular ones. WC Currency Switch works behind both: pages stay cached at the CDN, each shopper still sees their own currency, and the CDN can even tell the plugin which country a visitor is in, for free. For example, a shopper in Kuwait gets your cached product page from a nearby Bunny server, Bunny tells your site the visitor is in Kuwait, and the page shows prices in KWD.
How it works#
Every cached page carries each price in every enabled currency, and a small script in the visitor’s browser shows the one that matches the currency cookie. So the CDN can serve the same cached page to everyone. See How WC Currency Switch works with page caching for the details.
Two kinds of requests must never come from the CDN cache, because their answer is different for each visitor:
- The first-visit geo lookup. The script asks your site for the visitor’s currency through
/wp-admin/admin-ajax.php. A cached answer would give every new visitor the first visitor’s currency. - Currency switch links. A link such as
?wccs_cur=EURsets the currency and builds the page in that currency. A cached copy would be sent to everyone who opens that link.
How these are kept out of the cache depends on how you connect your site to the CDN.
Bunny CDN with Nahnu Cache Connector for Bunny.net#
There is nothing to set up in WC Currency Switch. When the connector is connected to your Bunny pull zone, the plugin uses the connector to:
- add a bypass rule at Bunny for
/wp-admin/admin-ajax.php*and/*wccs_cur=*, so geo lookups and switch links always reach your site. This rule is added even if the connector’s own Bypass: POST requests or Bypass: WP admin & PHP switches are off; - clear the Bunny cache when exchange rates move past your threshold.
The bypass rule is sent the first time you open an admin page after the connector is connected, and again after a plugin update changes the rule. Your pages themselves stay cached.
Bunny CDN with Super Page Cache#
If you use Super Page Cache with its Bunny connector:
- Go to WooCommerce > Currency Switch > Integrations.
- Under Cache Plugins, click Super Page Cache.
- Click Save Changes.
- Open any admin page. The plugin then adds a Bunny edge rule through Super Page Cache’s Bunny settings.
The edge rule tells Bunny to skip its cache for any request that carries the currency cookie. Super Page Cache removes all edge rules when it redeploys its own, so the plugin adds its rule again each time that happens. If adding the rule fails, the plugin waits an hour before trying again.
The plugin also clears the Bunny pull zone through these settings when exchange rates move past your threshold.
Cloudflare#
Cached pages on Cloudflare work through the price swap, with no extra setup. If you use Super Page Cache with Cloudflare, pick Super Page Cache under Cache Plugins: the plugin adds the currency cookie to Super Page Cache’s Cloudflare Worker bypass cookies.
Free geo detection from the CDN#
Both CDNs can tell your site the visitor’s country in a request header, so the plugin does not need to look up the IP address anywhere else.
- Bunny CDN sends the
CDN-RequestCountryCodeheader. - Cloudflare sends the
CF-IPCountryheader when its IP Geolocation option is on.
To use it:
- Go to WooCommerce > Currency Switch > Geo Detection.
- Under Detection source, pick CDN header (the default).
- Under Fallback when there is no CDN header, pick what to use when a request reaches your site without the header, for example WooCommerce Geolocation (the default).
- Click Save Changes.
When you open the Geo Detection tab through your CDN, the plugin shows the header it found, for example “This page came through a CDN: CDN-REQUESTCOUNTRYCODE = KW“.
Examples#
Bunny with Nahnu Cache Connector. A new visitor from Kuwait opens a cached product page. The page comes from Bunny’s cache. The script’s geo lookup goes past the cache to your site, which reads CDN-RequestCountryCode = KW and answers KWD. The script saves KWD in the cookie and shows the KWD prices that were already in the page.
Rates move. Your threshold is 1%. A rate refresh moves EUR by 1.5% against your store currency. The plugin clears the Bunny pull zone, so the next visitors get pages with the new prices.
Good to know#
- You only need one of the two Bunny setups. If Nahnu Cache Connector for Bunny.net is connected, the plugin uses it to clear the Bunny cache and does not also clear it through Super Page Cache.
- After you change any CDN or cache setting, clear the CDN cache once so old pages are removed.
Related docs#
- How WC Currency Switch works with page caching
- Clearing caches when exchange rates change
- Geo detection sources and the CDN fallback
- Cache plugin setup