I want to remove block product.info.addtocart from layout depends on some conditions

  • 1
    We need more information. – St3phan Feb 12 '19 at 13:16

You can use ifconfig on block

<block class=“…” ifconfig=“section/group/field” name=“product.info.addtocart” />

Or you can use helper:

<block name="product.info.addtocart" class="...">
    <action method="setTemplate">
        <argument name="template" xsi:type="helper" helper=“Vendorname\Modulename\Helper\Data::method”>
            <param name="name">Vendorname_Modulename::data/template.phtml</param>

The result in both cases it must to be boolean.

If you want to use in other cases, we need more details.


You can't remove block based on conditions in layout except system value(ifconfig) but you can do this from controller.


if(here your condition)
   $layout = $this->getLayout();
   $layout->unsetElement('product.info.addtocart'); //block name

I hope it helps 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.