• It does not make cart empty when you enter the quantity ZERO. On checkout page when i make quantity zero it does not consider it as empty it considers it as 01.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter ateebahamd

    (@ateebahamd)

    Actually I fixed this by modifying the code . here is the piece of code that I modified . would love if you can update the code and send an update in next version

    function cqoc_add_js(){
         
        if (  is_checkout() ) {
            $plugin_version = $this->plugin_version;
            wp_enqueue_style( 'cqoc_checkout', plugins_url( '/assets/css/change-quantity-on-checkout.css', __FILE__ ), '', $plugin_version, false );
            ?>  
            <script type="text/javascript">
                <?php  $admin_url = get_admin_url(); ?>
                jQuery("form.checkout").on("keypress", "input.qty", function( event ){
                    return event.charCode >= 48 && event.charCode <= 57;
                });
                
                jQuery("form.checkout").on("change", "input.qty", function( event ){
                    var quantityValue = jQuery(this).val();
                    if (quantityValue === '0') {
                        jQuery(this).val('');
                    }
                    
                    $form = jQuery( 'form.checkout' );
                    if ( $form[0].checkValidity() ){
                        var data = {
                            action: 'cqoc_update_order_review',
                            security: wc_checkout_params.update_order_review_nonce,
                            post_data: jQuery( 'form.checkout' ).serialize()
                        };
                        
                        jQuery.post( '<?php echo $admin_url; ?>' + 'admin-ajax.php', data, function( response )
                        {
                            jQuery( 'body' ).trigger( 'update_checkout' );   
                        });
                    }
                });
            </script>
            <?php  
        }
    }
    

    I added a check inside the change event listener for quantity inputs (jQuery("form.checkout").on("change", "input.qty", function( event ){) to detect if the quantity entered is ‘0’. If it is, the script sets the input field value to an empty string, effectively treating it as empty.

    Plugin Author bhavik.kiri

    (@bhavikkiri)

    Hi @ateebahamd,

    Thanks for sharing the code snippet.

    Certainly, I’ll be releasing the plugin update containing this fix soon.

    Regards,
    Bhavik

    • This reply was modified 6 months, 2 weeks ago by bhavik.kiri.
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘It does not make cart empty when you enter the quantity ZERO’ is closed to new replies.