Hey all,
Does anyone have experience with getting the total price from the check-out page? Right now, I’m just trying to send the value to the console to ensure that I can actually grab it.
Here’s what I’ve tried (every solution assumes an ID of total has been added to the total price in Webflow):
- Adding the following code to the page’s “Before </body> tag”:
<script>
var Webflow = Webflow || [];
Webflow.push(function () {
var totalPrice = document.getElementById('total');
console.log(totalPrice);
});
</script>
The result I get from this is that the entire line of HTML that contains the price as Inner Text is returned, like so:
<div id="total" data-wf-bindings="XXXXXXXX" data-wf-conditions="XXXX" class="w-commerce-commercecheckoutsummarytotal total-count-text">$90.30</div>
So I figured that if this is returned, then I should be able to just change my code from:
var totalPrice = document.getElementById('total');
to
var totalPrice = document.getElementById('total').innerText;
and get the Total, but the strange thing is that this sends a blank value to the console.
- Creating an HTML Embed on the checkout page itself and using Webflow’s Native Variables to pull the value:
I tried this as well, but I get a blank value altogether. In fact, if you look at the script in Chrome Dev Tools, the script itself just looks like:
var totalPrice =
(completely blank)
The weird thing is that neither of these solutions work but I can run the same code as I did in Solution #1 as a snippet (manually via Chrome Dev Tools) and get exactly the value I need. So, I think this is a timing issue? But I’m wrapping that code in the Webflow.js wrapper so I’m not sure what I’m doing wrong.
Any help would be greatly appreciated!
I’m just testing something out so I’ve got a dummy project set up to try and grab the value: Webflow - Donations + Round-ups