jeffrey149
Forum Replies Created
-
If it is not currently available, can you tell me how you compile the typescript into javascript so I can edit the typescript myself and update the existing javascript?
Hi, for people having similar issue, I have resolved this issue by implementing a custom php function in functions.php and a custom js script to make a call to the php function via ajax.
The javascript create cookie to keep track of user selected currency, and call functions.php via ajax.
The process is simply
- In javascript, get product ids in the current page using jquery [data-product-id]
- Ajax call to php function ({action, currency, product_ids})
- In php function, $WOOCS->set_currency(currency), the currency is default geolocation/cookie value if present.
- for each product ids, $_product->get_price_html()
- Return the data as {[product_price_html], current_currency}
- Back to javascript, refresh all product price by matching and replacing all span[data-product-id] with returned product_price_html
- Refresh mini cart(ajax call wc_cart_fragments_params), refresh shopping cart
I have tested and seems to work for my website, but test thoroughly in your website!
This is just to give some direction incase anyone face similar issue and don’t know where to start.I can now changed the woocommerce geolocate (with page caching support) to geolocate, remove the extra page redirect at the cost of couple ajax calls, saving ~2-3 seconds on initial page load, also reducing load by not having to cache multiple version of website (the added
v=
?parameter with woocommerce)