Woocommerce Mini Cart Widget Change Quantity

邮差的信 提交于 2019-12-11 17:47:51

问题


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!

来源:https://stackoverflow.com/questions/51846270/woocommerce-mini-cart-widget-change-quantity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!