Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <img src="<?php echo get_template_directory_uri() ?>/assets/img/minus.png" alt="" name="minus" class="minus"/>
- <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 ); ?>"/>
- <img src="<?php echo get_template_directory_uri() ?>/assets/img/plus.png" alt="" name="plus" class="plus"/>
- var cart = {
- init: function () {
- this.qty_click = this.qty_click.bind(this);
- $(document).on(
- 'click',
- '.quantity img',
- this.qty_click);
- qty_click: function (evt) {
- var $clicked = $(evt.target);
- var qty = $('.quantity').find('.qty');
- var currVal = qty.val();
- var $form = $('#doorCart');
- if ($clicked.is('.minus')) {
- evt.preventDefault();
- if (currVal > 0) {
- var newVal = parseFloat(qty.val()) - 1;
- } else {
- newVal = 0;
- }
- $clicked.next('.qty').attr('data-quantity', newVal).change();
- $clicked.next('.qty').attr( 'value', newVal ).change();
- $clicked.next('.qty').val( newVal ).change();
- };
- if ($clicked.is('.plus')) {
- evt.preventDefault();
- newVal = parseFloat(qty.val()) + 1;
- $clicked.prev('.qty').attr('data-quantity', newVal).change();
- $clicked.prev('.qty').attr( 'value', newVal ).change();
- $clicked.prev('.qty').val( newVal ).change();
- };
- }
- $(document).bind('ready ajaxComplete', function(){
- $('[name="update_cart"]').attr("disabled",false);
- });
- add_action( 'woocommerce_after_cart', 'custom_after_cart' );
- function custom_after_cart() {
- echo '<script>
- jQuery(document).ready(function($) {
- var upd_cart_btn = $(".update-cart-button");
- upd_cart_btn.hide();
- $("#doorCart").find(".qty").on("change", function(){
- upd_cart_btn.trigger("wc_update_cart");
- });
- });
- </script>';
- function action_enqueue_scripts() {
- wp_enqueue_script('update-cart', get_stylesheet_directory_uri().'/update-cart.js', array('jquery'));
- }
- add_action( 'wp_enqueue_scripts', 'action_enqueue_scripts' );
- function click_update_cart_btn(upd_cart_btn) {
- jQuery(".cart_item").parents('form').find('[name="update_cart"]');
- upd_cart_btn.trigger('click');
- }
- jQuery(document).ready(function($) {
- var update_cart;
- jQuery('body').delegate(".cart_item .qty").on("change", function(){
- if(update_cart != null){
- clearTimeout(update_cart);
- }
- update_cart = setTimeout(click_update_cart_btn, 1000);
- });
- });
Add Comment
Please, Sign In to add comment