0

How to change the label of add to cart to pre order on all magento 2.4.5 based on the below conditions:

if(qty<0 , product is salable and getBackorders()/true )

to show pre order else add to cart.

Please suggest a way to implement this.

1 Answer 1

0
  1. First create catalog_category_view.xml into your custom extension at following path.

app\code\Vendor\Extension\view\frontend\layout\catalog_category_view.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="2columns-left" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="category.products.list">
            <action method="setTemplate">
                <argument name="template" xsi:type="string">Vendor_Extension::catalog/product/list.phtml</argument>
            </action>
        </referenceBlock>
    </body>
</page>
  1. Now copy the magento default category list file from :

vendor/magento/module-catalog/view/frontend/templates/product/list.phtml

to

app\code\Vendor\Extension\view\frontend\templates\catalog\product\list.phtml

  1. now into your extension file, you need to put conditions before Add To Cart Button according to your requirements.

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.