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.