Title: Cart Total issues
Last modified: June 8, 2020

---

# Cart Total issues

 *  Resolved [tugbucket](https://wordpress.org/support/users/tugbucket/)
 * (@tugbucket)
 * [5 years, 11 months ago](https://wordpress.org/support/topic/cart-total-issues/)
 * `$( document.body ).on('click', 'a.rpress-clear-cart', function(e) {`
    needs 
   to include: `$('span.rpress-cart-quantity').text(response.cart_quantity);` in
   it’s success function.
 * in `function rpress_clear_cart_items() {` it needs to include: `$return['cart_quantity']
   = rpress_get_cart_quantity();`
 * The “clear cart” doesn’t update the cart count but the above resolves that.
 * I also wanted to have the cart link in my nav show the current cart count so 
   you can use:
 *     ```
       	$('.menu-item:last-child a').append(' (<span class="rpress-cart-quantity">'+localStorage.getItem('tug_bg_cartCount')+'</span>)');
       	$('body').on('DOMSubtreeModified', '.rpress-cart-badge.rpress-cart-quantity', function(){
       		localStorage.setItem('tug_bg_cartCount', $(this).text());
       	});
       ```
   
 * I am specifically adding the value to my last nav item so the example might not
   work for everyone. But, since your plugin has an options page, you should be 
   able to whip up a method for this.
 * And, the cart total doesn’t reflect the true total number of items. For example,
   if I add and item, set the quantity to 3, the “receipt” shows 3x but the total
   items is 1 eg: Total ( 1 Items) . A simple method :
 *     ```
       	var itemquantity = 0;
       	$('.rpress-cart-item-qty.qty-class').each(function(){
       		itemquantity += parseInt($(this).text(), 10);
       	});
       	$('.rpress-cart-quantity').text(itemquantity);
       ```
   
 * That will count the actual number of items ordered instead of each row of an 
   order reflected the correct total.
 * Side note, adding an “s” to item when there is only 1 is pretty straight forward
   for the PHP part:
 *     ```
       <?php 
       	$s = '';
       	if($cart_quantity != 1){
       		$s = 's';
       	}
       ?>
       <?php _e( ' Item'.$s.')', 'restropress' ); ?>
       ```
   
 * Now modifying the “s” in the ajax return will take a little more than that but
   it’s a start.

The topic ‘Cart Total issues’ is closed to new replies.

 * ![](https://ps.w.org/restropress/assets/icon-256x256.gif?rev=3216477)
 * [RestroPress - Online Food Ordering System](https://wordpress.org/plugins/restropress/)
 * [Support Threads](https://wordpress.org/support/plugin/restropress/)
 * [Active Topics](https://wordpress.org/support/plugin/restropress/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/restropress/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/restropress/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [tugbucket](https://wordpress.org/support/users/tugbucket/)
 * Last activity: [5 years, 11 months ago](https://wordpress.org/support/topic/cart-total-issues/)
 * Status: resolved