Sum items

I’ve tried searching for this but keep getting results on append(), etc.

I’m building a cart that adds items via jQuery. Basically you select the product and click the ‘add to cart’ button and then it gets added to the page via append. Very simple.

What I’m trying to do is total up the dollar amounts of each item added to the cart, but I can’t figure out how to do that. How do I keep a running tally of prices throughout my different functions?

Whenever I am facing a problem like this my approach is to think “how would I do it manually?”

Afterall, computers are only useful for performing simple tasks (we can do ourselves) at a very fast rate.

In this case, I would expect that when I am viewing my cart (all the goods I have assembled to buy) the total would be available. And so, it seems the time to devise a total is [only] when you are displaying the entire cart of items. In that view/page which displays the cart you can add the individual prices (and calculate tax, shipping, etc).

Sorry, should have been more clear. The products and the cart are all on the same page, so I have to update the total as each item is added.

Resolved. Using PHP and $.get(). Calculating the totals in a PHP SESSION and loading into the div when adding to the cart. It’s amazing what some sleep will do. :slight_smile:

$.get('lib/order_totals.php', function(data) {
    $('#totals').html(data);
});