Jump to content

Currency Symbol Change

Recommended Posts

Posted

Site URL: https://www.hampseshop.com/

Hi, I'm from Maldives, and I understand that squarespace does not have our currency supported yet. However, I have changed the currency symbol using a css code. But the problem is when ever I change a variant of a product like color, currency symbol chances back to default. Can someone help me out.

.sqs-money-native:before {
   content:'₦ '!important;
 }

 

Posted

Add to Home > Settings > Advanced > Code Injection > Footer

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<script>
  window.Squarespace.onInitialize(Y, function(){  
		$(".ProductItem-details .product-price").html(function() { 
          return $(this).html().replace("$", "MRF");  
    });
	});
</script>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Posted

Thank you for responding,

I have removed the old code and did what you have adviced, but it's not working.

Am I doing it wrong?

Posted

I'm attaching a video with this code in the work

.sqs-money-native:before {
   content:'MRF '!important;
 }

this code is injected in design > custom css, it doesn't work when I inject it to Home > Settings > Advanced > Code Injection > Footer.

The code that you have doesn't work in either one, also I have tried with both codes.

Posted

Add to Home > Settings > Advanced > Code Injection > Footer

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<script>
  window.Squarespace.onInitialize(Y, function(){  
		$(".ProductItem-details .product-price").html(function() { 
          return $(this).html().replace("$", "MRF");  
    });
	});
</script>

I have tried this one but this doesn't work for me, what am I doing wrong?

I have also tried with and without the code I posted earlier and doesn't wrong either.

 

.sqs-money-native:before {
   content:'MRF '!important;
 }

Appreciate you responding so quickly.

Thank you

Posted (edited)

@Hamps Another alternative solution is to leverage the MutationObserver Web API which listens for changes to that .product-list element and replaces the $ with MVR whenever it detects that something has changed with that element:

(function () {

  // Select the node that will be observed for mutations
  var productSummaryPrice = document.querySelector('.ProductItem-summary .product-price');

  // Exit if target node isn't found.
  if(!productSummaryPrice) return;

  // Options for the observer (which mutations to observe)
  var config = { childList: true };

  // Create an observer instance linked to the callback function
  var observer = new MutationObserver(function () {
    var text = productSummaryPrice.textContent;
    productSummaryPrice.textContent = text.replace('$', 'MVR ');
  });

  // Start observing the target node for configured mutations
  observer.observe(productSummaryPrice, config);

})();

Make sure the code above is between <script> tags, example:

<script>
  // Add JS code here
</script>

 

Edited by jpeter

Full stack developer who loves helping people out with anything web related. If you'd like to support me, buy me a coffee!

Posted

Jpeter

thank you for the response, this is very new to me. Could you please let me know a step by step guide.

Thank You again

 

  • 8 months later...
Posted
On 6/9/2020 at 8:25 PM, jpeter said:

@Hamps Another alternative solution is to leverage the MutationObserver Web API which listens for changes to that .product-list element and replaces the $ with MVR whenever it detects that something has changed with that element:


(function () {

  // Select the node that will be observed for mutations
  var productSummaryPrice = document.querySelector('.ProductItem-summary .product-price');

  // Exit if target node isn't found.
  if(!productSummaryPrice) return;

  // Options for the observer (which mutations to observe)
  var config = { childList: true };

  // Create an observer instance linked to the callback function
  var observer = new MutationObserver(function () {
    var text = productSummaryPrice.textContent;
    productSummaryPrice.textContent = text.replace('$', 'MVR ');
  });

  // Start observing the target node for configured mutations
  observer.observe(productSummaryPrice, config);

})();

Make sure the code above is between <script> tags, example:


<script>
  // Add JS code here
</script>

problem.thumb.jpg.c00518b79c64cf7dc8b9dc89b4a016d8.jpg645854690_worksfine.thumb.jpg.a2734bc50dccd5af2202097458206eb7.jpg

Thank you for this code. Worked perfectly for my site too. 

I have one minor problem; I used this code to replace € sign with 'TL' text but it cancelled out sale price display for products with variants where the original price is crossed out and the sale price is display in red (or in the color your preference). Is there a way to fix this?

It works fine for single products which has no variants. Attaching two pics to explain what I mean. Appreciate your help.

 

Posted
2 hours ago, Beyond said:

Thank you for this code. Worked perfectly for my site too. 

I have one minor problem; I used this code to replace € sign with 'TL' text but it cancelled out sale price display for products with variants where the original price is crossed out and the sale price is display in red (or in the color your preference). Is there a way to fix this?

It works fine for single products which has no variants. Attaching two pics to explain what I mean. Appreciate your help.

 

Regarding the problem; I just figured out original price and the sale price are both shown as the original price; hence whatever change I make the price (font color etc) applies to the sale price too. How do I separate them as sale and original price? I think it is a problem caused by mutation coding but I need it I cannot erase it. Thank you

Posted

@Beyond

Try the JS code below instead, which maintains the HTML structure rather than override it. 

(function () {

  // Select the node that will be observed for mutations
  var productSummaryPrice = document.querySelector('.ProductItem-summary .product-price');

  // Exit if target node isn't found.
  if(!productSummaryPrice) return;

  // Options for the observer (which mutations to observe)
  var config = { childList: true };

  // Create an observer instance linked to the callback function
  var observer = new MutationObserver(function () {
    var html = productSummaryPrice.innerHTML;
    productSummaryPrice.innerHTML = html.replace(/€/g, 'TL ');
  });

  // Start observing the target node for configured mutations
  observer.observe(productSummaryPrice, config);

})();

 

Full stack developer who loves helping people out with anything web related. If you'd like to support me, buy me a coffee!

  • 1 year later...
Posted
On 6/9/2020 at 1:24 PM, tuanphan said:

Add to Home > Settings > Advanced > Code Injection > Footer

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<script>
  window.Squarespace.onInitialize(Y, function(){  
		$(".ProductItem-details .product-price").html(function() { 
          return $(this).html().replace("$", "MRF");  
    });
	});
</script>

 

Hello;

Thank you. Working well on desktop. However, when selecting a variant on mobile, the entire page and dropdown are unresponsive (freezes).

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.