WooCommerce “plus” and “minus” buttons in the quantity field are the best way to increase or decrease the number of items in your cart.
By default, the quantity field in WooCommerce is a numeric type input. It looks like a field with up and down arrows. By clicking these arrows, shoppers can increase or decrease the quantity of items in the cart or on the product page. There are more elegant types: plus and minus signs instead of arrows look much better. In this post, I share snippets of how to add plus and minus buttons to the quantity field in WooCommerce.
The default quantity field:

Quantity field with plus and minus buttons:

There are many posts and snippets on replacing arrows with plus and minus signs, but most of them are either shopping carts with outdated WooCommerce code, or shopping carts without a feature to automatically update the amount of purchases. And one more problem, the developers suggest overriding the quantity input template. I tried many different snippets. None of them were perfect. So, I changed the code, and alt: I have code that:
1. Add plus and minus signs.
2. Hide the default arrows
3. The cart automatically updates when you click plus or minus and recalculate the total.
4. No need to override Quantity-input.php template.
5. And add beautiful SVG plus and minus signs ?
Step 1 – add plus and minus buttons
Add the code below to your child theme’s function.php file or custom PHP snippets plugin:
</span></span>
<span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
add_action('woocommerce_after_quantity_input_field', 'ab_quantity_plus');</span></span>
<span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
функция ab_quantity_plus() {</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
echo '<div class="plus"> <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/ svg"><path d="M15.5 9.4h-4.9V4.5a.6.6 0 10-1.2 0v4.9H4.5a.6.6 0 000 1.2h4.9v4.9a.6.6 0 001.2 0v-4.9h4.9a. 6.6 0 100-1.2z" fill="currentColor"></path></svg> </div>';</span></span>
}
<span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
add_action('woocommerce_before_quantity_input_field', 'ab_quantity_minus');</span></span>
<span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
функция ab_quantity_minus() {</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
echo '<div class="minus"> <svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/ svg"><path d="M15.5 9.45h-11a.55.55 0 000 1.1h11a.55.55 0 000-1.1z" fill="currentColor"></path></svg> </div>';</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
}</span></span>
<span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
Step 2 – add the JavaScript code
This jQuery code:
1. increase and decrease the number of items when the customer clicks the plus and minus button
2. automatically update the cart (recalculate the total amount).
Add this code to the end of your child theme’s function.php file in your own PHP snippet plugin.
[язык исходного кода="php"] функция ab_add_quantity_script(){ если( ! is_admin() ) { ?> <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAAAEAAAIBRAA7" data-wp-preserve="%3Cscript%3E%0AjQuery(document).ready(function(%24)%7B%0A%24( document).on('click'%2C%20'.plus'%2C%20function(e)%20%7B%0A%20%20%20%20%24input%20%3D%20%24(это) .prev('input.qty')%3B%0A%20%20%20%20var%20val%20%3D%20parseInt(%24input.val())%3B%0A%20%20%20%20var% 20step%20%3D%20%24input.attr('step')%3B%0A%20%20%20%20step%20%3D%20'неопределено'%20!%3D%3D%20typeof(шаг)% 20%3F%20parseInt(шаг)%20%3A%201%3B%0A%20%20%20%20%24input.val(%20val%20%2B%20step%20).change()%3B%0A %09%24('%5Bname%3D%22update_cart%22%5D').trigger('click')%3B%20%0A%7D)%3B%0A%24(document).on('click'% 2C%20'.minus'%2C%20function(e)%20%7B%0A%20%20%20%20%24input%20%3D%20%24(this).next('label').next ('input.qty')%3B%0A%20%20%20%20var%20val%20%3D%20parseInt(%24input.val())%3B%0A%20%20%20%20var%20step% 20%3D%20%24input.attr('шаг')%3B%0A%20%20%20%20step%20%3D%20'неопределено'%20!%3D%3D%20typeof(шаг)%20% 3F%20parseInt(шаг)%20%3A%201%3B%0A%20%20%20%20if%20(val%20%3E%200)%20%7B%0A%20%20%20%20% 20%20%20%20%24input.val(%20val%20-%20step%20).change()%3B%0A%20%20%20%20%7D%0A%09%20%24(' %5Bname%3D%22update_cart%22%5D').trigger('click')%3B%20%0A%7D)%3B%0A%7D)%3B%09%09%0A%3C%2Fscript%3E" data-mce-resize="false" data-mce-placeholder="1" class="mce-object" width="20" height="20" alt="<script>" title="<скрипт>" /> <?php } } add_action('wp_footer', 'ab_add_quantity_script'); [/исходный код]
Step 3 – Add CSS code to remove the default arrows from the input
This code is added to the style.css file of your child theme or in Appearance → Settings → Advanced CSS. Or, if you are using Elementor PRO, you can add this code under Elementor → Custom Code (add it to </body> – End).
</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
.quantity input::-webkit-outer-spin-button,</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
.quantity input::-webkit-inner-spin-button {</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
дисплей: нет;</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
маржа: 0;</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
}</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
.количество вход.количество {</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
внешний вид: текстовое поле;</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
-webkit-внешний вид: нет;</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
-moz-внешний вид: текстовое поле;</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
}</span></span><span style="vertical-align: inherit;"><span style="vertical-align: inherit;">
Step 4: Formatting the plus and minus buttons and the input field.
This step will depend on the theme you are using. You can customize it on your own. I created this CSS using the Hello theme from the Elementor plugin.
[код языка="css"] /* стиль ввода */ .woocommerce .input-text.qty { отступ: 0 !важно; выравнивание текста: по центру! Важно; минимальная высота: 18 пикселей; максимальная высота: 18 пикселей; ширина: 2ем; граница: нет; фон: прозрачный; } .продукт-количество .количество, .продукт .количество { дисплей: гибкий; выровнять-элементы: по центру; оправдание-содержание: центр; } th.product-количество { выравнивание текста: по центру } .продукт .корзина { дисплей: гибкий; выровнять-элементы: по центру; } /* стиль кнопок плюс и минус */ .минус, .плюс { дисплей: гибкий; выровнять-элементы: по центру; цвет: #454545; отступ: 3 пикселя; высота: 26 пикселей; ширина: 26 пикселей; граница: сплошная 1 пиксель #454545; радиус границы: 50 пикселей; } .минус:наведение, .plus:наведите { цвет: #454545; курсор: указатель; } [/код]
My clients ask me to add or change a lot of things in their WooCommerce store. For example, my client recently asked me to add a notification for how much is left for free shipping. If you want the same, read my post. Display “Left to free shipping” notice on the shopping cart.