• Resolved Nouman Qamar

    (@noumanqamar450)


    i need mini cart quantity update. i using below code, but its not working, plz check this code and tell me

    //Add mini cart quantity field
    add_filter( 'woocommerce_widget_cart_item_quantity', 'add_mini_cart_quantity_fields', 10, 3 );
    function add_mini_cart_quantity_fields( $html, $cart_item, $cart_item_key ) {
        $product_price = apply_filters( 'woocommerce_cart_item_price', WC()->cart->get_product_price( $cart_item['data'] ), $cart_item, $cart_item_key );
    
        return woocommerce_quantity_input( array('input_value' => $cart_item['quantity']), $cart_item['data'], false ) . $product_price;
    }
    
    add_filter( 'wp_ajax_nopriv_ajax_update_mini_cart', 'ajax_update_mini_cart' );
    add_filter( 'wp_ajax_ajax_update_mini_cart', 'ajax_update_mini_cart' );
    
    //Update mini cart
    function ajax_update_mini_cart() {
      echo wc_get_template( 'cart/mini-cart.php' );
      die();
    }
    
    // -------------
    // 2. Trigger update quantity script
      
    add_action( 'wp_footer', 'add_cart_quantity_plus_minus' );
      
    function add_cart_quantity_plus_minus() {
     
       if ( ! is_product() && ! is_cart() ) return;
        
       wc_enqueue_js( "   
               
            // Update Mini Cart
            $(document).ready(function () {
                jQuery('name=quantity').on('change', 'input', function () {
                    $.post(
                    woocommerce_params.ajax_url,
                    { action: 'ajax_update_mini_cart' }, // This must match the name of your wp_ajax filter
                    function (response) {
                        $('#mode-mini-cart').html(response);
                    }
                    );
                    console.log('s');
                });
                
            });
            
       " );
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator t-p

    (@t-p)

    Are you using a plugin for CART? If yes, what plugin?

    Or is this a feature of your theme? If yes, what theme?

    • This reply was modified 3 years, 10 months ago by t-p.
    Thread Starter Nouman Qamar

    (@noumanqamar450)

    I use extra feature in our theme

    • This reply was modified 3 years, 10 months ago by Nouman Qamar.
    Moderator t-p

    (@t-p)

    I recommend asking at your theme’s support so its developers and support community can help you with this.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Add mini card quantity Update cate’ is closed to new replies.