0

I am trying to make quantity increment plus minus button on product listing page for magento 2. I have see php cuong made a good module but that only works on details page. How I can add functionality on listing page.

1
  • kindly check my answer below. Dec 12, 2020 at 14:04

1 Answer 1

1

Add the below code to your list.phtml before the "Add to Cart" button.

<div class="field qty">
    <div class="control qty-change">
        <?php $id = "qty_".$_product->getId(); ?>
        <button  type="button" class="reduced items" onclick="var result = document.getElementById('<?= $id ?>'); var qty = result.value; if( !isNaN( qty ) && qty > 1 ) result.value--;return false;">-</button>
        <input type="text"
               name="qty"
               id="<?= $id ?>"
               value="1"
               title="<?= /* @escapeNotVerified */ __('Qty') ?>"
               class="input-text qty"
               data-validate="<?= $block->escapeHtml(json_encode($block->getQuantityValidators())) ?>"
               />
        <button  type="button" class="increase items" onclick="var result = document.getElementById('<?= $id ?>'); var qty = result.value; if( !isNaN( qty )) result.value++;return false;">+</button>
    </div>
</div>

I Hope this will work for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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