daily pastebin goal
63%
SHARE
TWEET

Display quantity of each product added to cart ( on collecti

mikele027 Jan 12th, 2018 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. http://featherless.ca/projects/devwiki/wp-content/uploads/2017/11/Screenshot-300x127.png
  2.  
  3.     {% assign product_qty_none = 0 %}
  4.     {% for line_item in cart.items %}
  5.     {% if line_item.product_id == product.id %}
  6.     {% capture product_qty_none %}{{ line_item.quantity }}{% endcapture %}
  7.     {% endif %}
  8.     {% endfor %}
  9. <div class="qty-holder {% if product_qty_none == 0 %}qty_holder_hidden{% endif %}">
  10.    <h3>{{ product_qty_none | times: 1 }}</h3><h4>IN CART</h4>
  11. </div>
  12. .qty_holder_hidden {
  13.    display: none;
  14. }
  15.  <script>
  16.   jQuery( ".product__add-to-cart" ).on( "click", function() {
  17.     var quantity_selector_value = jQuery(this).prev().find('input[type="number"]').val();
  18.     var quantity_default_value = parseInt(jQuery(this).parents('.collection__item').find('.qty-holder').text(), 10);
  19.     var quantity_new_value = parseInt(quantity_selector_value, 10) + parseInt(quantity_default_value, 10);
  20.     jQuery(this).parents('.collection__item').find('.qty-holder').removeClass('qty_holder_hidden');
  21.     jQuery(this).parents('.collection__item').find('.qty-holder h3').text(quantity_new_value);
  22.   });
  23. </script>
RAW Paste Data
Top