Personalized checkout and custom promotions with Shopify Scripts
I am new to coding and have searched online and gotten most of the code working, but now can't seem to get the product price to render into the code.
I have a dummy price in here of 8.99 right now. How can I get the product price to be used here? This is on Dawn product page in a custom liquid block.
<span style="color: #ff0000">
<div id="current_date">
<script>
var number =8.99.toFixed(1);
var percentToGet = 10;
var percentAsDecimal = (percentToGet / 100);
var percent = percentAsDecimal * number;
date = new Date();
year = date.getFullYear();
month = date.getMonth() + 1;
day = date.getDate() + 1;
document.getElementById("current_date").innerHTML ="<strong>Free Shipping Plus use SAVE10 at checkout for an additional $"+ percent + " OFF - Expires "+ month + "/" + day + "/" + year;
</script>
</div>
</span>
Solved! Go to the solution
This is an accepted solution.
helllo there
To render the product price in the code, you'll need to retrieve the price value from the product object in your liquid block.
Assuming that you have access to the product object, you can replace the hard-coded price value of 8.99 with the actual product price value.
Here's an example of how you could modify the code to include the product price value:
<span style="color: #ff0000">
<div id="current_date">
<script>
var productPrice = {{ product.price | money_without_currency }};
var percentToGet = 10;
var percentAsDecimal = (percentToGet / 100);
var percent = percentAsDecimal * productPrice;
date = new Date();
year = date.getFullYear();
month = date.getMonth() + 1;
day = date.getDate() + 1;
document.getElementById("current_date").innerHTML ="<strong>Free Shipping Plus use SAVE10 at checkout for an additional $"+ percent + " OFF - Expires "+ month + "/" + day + "/" + year;
</script>
</div>
</span>
In this modified code, the product price value is retrieved using the {{ product.price | money_without_currency }}
liquid object. This object returns the price of the product in the format "XX.XX".
We then use this value to calculate the percent discount and display the final message.
If this fixed your issue, likes and accepting as a solution are highly appreciated.
Build an online presence with our custom built Shopify Theme EcomifyTheme
This is an accepted solution.
helllo there
To render the product price in the code, you'll need to retrieve the price value from the product object in your liquid block.
Assuming that you have access to the product object, you can replace the hard-coded price value of 8.99 with the actual product price value.
Here's an example of how you could modify the code to include the product price value:
<span style="color: #ff0000">
<div id="current_date">
<script>
var productPrice = {{ product.price | money_without_currency }};
var percentToGet = 10;
var percentAsDecimal = (percentToGet / 100);
var percent = percentAsDecimal * productPrice;
date = new Date();
year = date.getFullYear();
month = date.getMonth() + 1;
day = date.getDate() + 1;
document.getElementById("current_date").innerHTML ="<strong>Free Shipping Plus use SAVE10 at checkout for an additional $"+ percent + " OFF - Expires "+ month + "/" + day + "/" + year;
</script>
</div>
</span>
In this modified code, the product price value is retrieved using the {{ product.price | money_without_currency }}
liquid object. This object returns the price of the product in the format "XX.XX".
We then use this value to calculate the percent discount and display the final message.
If this fixed your issue, likes and accepting as a solution are highly appreciated.
Build an online presence with our custom built Shopify Theme EcomifyTheme
Thank you so very much for the fast response. This worked perfectly.
We want to take a moment to celebrate the incredible ways you all engage with the Shopi...
By JasonH Oct 15, 2024Starting a B2B store is a big undertaking that requires careful planning and execution. W...
By JasonH Sep 23, 2024By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024