Guest User

Untitled

a guest
Feb 19th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. <img src="<?php echo get_template_directory_uri() ?>/assets/img/minus.png" alt="" name="minus" class="minus"/>
  2. <input type="number" step="<?php echo esc_attr( $step ); ?>" min="<?php echo esc_attr( $min_value ); ?>" max="<?php echo esc_attr( $max_value ); ?>" name="<?php echo esc_attr( $input_name ); ?>" value="<?php echo esc_attr( $input_value ); ?>" data-quantity="<?php echo esc_attr( $input_value ); ?>" title="<?php echo esc_attr_x( 'Qty', 'Product quantity input tooltip', 'woocommerce' ) ?>" class="input-text qty text exo2Medium" size="4" pattern="<?php echo esc_attr( $pattern ); ?>" inputmode="<?php echo esc_attr( $inputmode ); ?>"/>
  3. <img src="<?php echo get_template_directory_uri() ?>/assets/img/plus.png" alt="" name="plus" class="plus"/>
  4.  
  5. var cart = {
  6. init: function () {
  7. this.qty_click = this.qty_click.bind(this);
  8. $(document).on(
  9. 'click',
  10. '.quantity img',
  11. this.qty_click);
  12. qty_click: function (evt) {
  13. var $clicked = $(evt.target);
  14. var qty = $('.quantity').find('.qty');
  15. var currVal = qty.val();
  16. var $form = $('#doorCart');
  17.  
  18. if ($clicked.is('.minus')) {
  19. evt.preventDefault();
  20. if (currVal > 0) {
  21. var newVal = parseFloat(qty.val()) - 1;
  22. } else {
  23. newVal = 0;
  24. }
  25.  
  26. $clicked.next('.qty').attr('data-quantity', newVal).change();
  27. $clicked.next('.qty').attr( 'value', newVal ).change();
  28. $clicked.next('.qty').val( newVal ).change();
  29. };
  30. if ($clicked.is('.plus')) {
  31. evt.preventDefault();
  32. newVal = parseFloat(qty.val()) + 1;
  33.  
  34. $clicked.prev('.qty').attr('data-quantity', newVal).change();
  35. $clicked.prev('.qty').attr( 'value', newVal ).change();
  36. $clicked.prev('.qty').val( newVal ).change();
  37. };
  38. }
  39. $(document).bind('ready ajaxComplete', function(){
  40. $('[name="update_cart"]').attr("disabled",false);
  41. });
  42.  
  43. add_action( 'woocommerce_after_cart', 'custom_after_cart' );
  44. function custom_after_cart() {
  45. echo '<script>
  46. jQuery(document).ready(function($) {
  47. var upd_cart_btn = $(".update-cart-button");
  48. upd_cart_btn.hide();
  49. $("#doorCart").find(".qty").on("change", function(){
  50. upd_cart_btn.trigger("wc_update_cart");
  51. });
  52. });
  53. </script>';
  54.  
  55. function action_enqueue_scripts() {
  56. wp_enqueue_script('update-cart', get_stylesheet_directory_uri().'/update-cart.js', array('jquery'));
  57. }
  58. add_action( 'wp_enqueue_scripts', 'action_enqueue_scripts' );
  59.  
  60. function click_update_cart_btn(upd_cart_btn) {
  61. jQuery(".cart_item").parents('form').find('[name="update_cart"]');
  62. upd_cart_btn.trigger('click');
  63. }
  64.  
  65. jQuery(document).ready(function($) {
  66. var update_cart;
  67. jQuery('body').delegate(".cart_item .qty").on("change", function(){
  68. if(update_cart != null){
  69. clearTimeout(update_cart);
  70. }
  71. update_cart = setTimeout(click_update_cart_btn, 1000);
  72. });
  73. });
Add Comment
Please, Sign In to add comment