Woocommerce Mini Cart Widget Change Quantity

2019-08-28 20:12发布

问题:

I've been researching and cannot find a solution to this. I am trying to add or remove items individually from the Default Woocommerce mini cart widget cart. Items are being added to the cart using AJAX.

Currently, it's only possible to remove all quantities of the product.

For example: If user adds 3 Shirt's to the cart, I want to allow the user to remove AND add 1 at a time instead of forcing them to remove the entire amount (all 3) at once.

I have found that it's possible to add these buttons into the cart by hooking into the Mini Cart with the following code. I cannot get these to display, and my mini cart goes completely blank.

Code to Add + and - buttons:

    <?php
//btn add
echo do_shortcode('[add_to_cart id="'.$cart_item['product_id'].'" show_price="false" btn_text="+" class="btnAdd" ]');
//btn minus, the cart_item_key and $cart_item['.. is available already in scope.
echo '<a class="btnMinus" onClick="updateQty(\''.$cart_item_key.'\','.($cart_item['quantity']-1).')"> - </a>';
?>

Screenshot of mini cart example:

Seems as it is definitely possible as there is a paid plugin which offers this functionality. But I would like to avoid this for dependency purposes and bloating unnecessary code.

Thanks for all the help/suggestions!