magentomagento-1.6

Programmatically remove block from layout


I want to remove the product_options_wrapper block from the product view page according to the logedin user via frontend router controller.

I know that I can programmatically append a new block but I didn't find a remove function. :-(

Tried sth. like that

$this->getLayout()->unsetBlock('product_options_wrapper');

$this->getLayout()->getBlock('product.info')->remove('product_options_wrapper');

But nothing works.


Solution

  • The OP code should work, if it used the correct block name, which is product.info.options.wrapper, as opposed to the block alias.

    $this->loadLayout();
    //e.g. 
    if (Mage::getSingleton('customer/session')->getCustomerGroupId() == [id]){
         $this->getLayout()->unsetBlock('product.info.options.wrapper');
    }
    $this->renderLayout();