I'm a little new to the magento 2 area and I'm not finding a way to put a quantity counter to be added to the cart next to "add to cart" in the catalog area, as in the illustrative image, I'm using a luma copy as theme, could someone give me a north. [![enter image description here][1]][1]

Similar to what is already in the cart, but I need to bring it to the catalog part.

[![enter image description here][2]][2]

Magento 2.3.3 Theme: Luma

1 Answer 1


You just need to override the list.phtml file under


and add below code after Add To Cart button and inside form tag:

<?php $postParams = $block->getAddToCartPostParams($_product); ?>
<form data-role="tocart-form" action="<?=  $postParams['action'] ?>" method="post">
    <input type="hidden" name="product" value="<?= $postParams['data']['product'] ?>">
    <input type="hidden" name="<?= Action::PARAM_NAME_URL_ENCODED ?>" value="<?= $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">
    <?= $block->getBlockHtml('formkey') ?>
    <div class="field qty">
        <div class="control quantity-box" data-id="<?php echo $_product->getId(); ?>">
            <input type="number"
                id="qty-<?php echo $_product->getId(); ?>"
                value="<?php echo '1' ?>"
                title="<?php echo __('Qty') ?>" class="input-text qty"
    <button type="submit"
            title="<?= $block->escapeHtml(__('Add to Cart')) ?>"
            class="action tocart primary">
        <span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>

enter image description here

I have added qty box before Add To Cart Button in my code. but you can add as per your requirement. and the quantity box should be inside the form tag.

Hope this will help you!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.