kreamweb
5/26/2016 - 12:23 PM

this code fix the problem of update the quantity automatically when the theme use a different quantity field

this code fix the problem of update the quantity automatically when the theme use a different quantity field

var request;
    $(document).on( 'click', '.product-quantity input', function(e){

        if( typeof request !== 'undefined' ){
            request.abort();
        }

        var $t = $(this),
            $input_quantity = $t.closest('.product-quantity').find('.input-text.qty'),
            name = $input_quantity.attr('name'),
            value = $input_quantity.val(),
            item_keys = name.match(/[^[\]]+(?=])/g);

        //this is not necessary for some theme like flatsome
        if( $t.hasClass('plus') ){
            value ++;
        }

        if( $t.hasClass('minus') ){
            value --;
        }
        //end
        
        var request_info = 'action=yith_ywraq_action&ywraq_action=update_item_quantity&quantity='+value+'&key='+item_keys[0];

        request = $.ajax({
            type   : 'POST',
            url    : ywraq_frontend.ajaxurl.toString().replace( '%%endpoint%%', 'yith_ywraq_action' ),
            dataType: 'json',
            data   : request_info
        });
    });