I have certain products, which customers can buy only one.
So whether needs to remove Qty box for that products only or can be managed from settings?
There is a config in Admin: Log in to Admin > PRODUCTS > Catalog > choose a Product > Advanced Inventory > Maximum Qty Allowed in Shopping Cart > set to 1.
Overwrite as below
magento\app\design\frontend\Vendor\YourThemeName\Magento_Catalog\templates\product\view\addtocart.phtml
Replace
if ($block->shouldRenderQuantity())
With
if ($block->shouldRenderQuantity() && ($_product->getExtensionAttributes()->getStockItem()->getMaxSaleQty() != 1)):
U need to add
$_product->getExtensionAttributes()->getStockItem()->getMaxSaleQty()
magento\vendor\magento\module-catalog\view\frontend\templates\product\view\addtocart.phtml
$_product->getStockItem($_product->getId())
still max_sale_qty
missing
$_product->getExtensionAttributes()->getStockItem()->getMaxSaleQty()
Commented
Jan 17, 2017 at 10:06
Create an after plugin for shouldRenderQuantity. In your di.xml, add this.
<type name="Magento\Catalog\Block\Product\View">
<plugin name="Vendor_Module::configurable-no-render-quantity-field" type="Vendor\Module\Plugin\Block\Product\View" />
</type>
Then in your plugin, do something like this:
public function afterShouldRenderQuantity(\Magento\Catalog\Block\Product\View $subject, $result)
{
if ($subject->getProduct()->getTypeId() === \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE) {
return false;
}
return $result;
}
Modify the if condition in my sample to achieve what you want.