Solved

How can I integrate the product price into my custom liquid block code?

U087991
Tourist
10 0 2

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>

Accepted Solution (1)

EcomGraduates
Shopify Partner
588 48 79

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.

 

View solution in original post

Replies 2 (2)

EcomGraduates
Shopify Partner
588 48 79

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.

 

U087991
Tourist
10 0 2

Thank you so very much for the fast response. This worked perfectly.