1

On my Magento 2 store I have a static block that outputs a message to inform customers that the prices are not currently available. On my template files I'd like to wrap the prices and Add to Cart buttons to an if/else statement, so those elements are not created if that static block is enabled:

if ( 'static block "disable_store" is active' ) {
    echo "No prices available at this time";
} else {
    ... show the price etc ...
}

The bit I can't figure out is what to put on the if line. Please note that I don't want to output the contents of the block here, just to check if it's enabled or not.

1

Not need to check the if the block is enabled or not because magento2's toHtml() always return the html when static block is enabled. You can use the below code for checking:

$html = $this->getLayout()
->createBlock('Magento\Cms\Block\Block')->setBlockId(BLOCK_ID)->toHtml();

if($html){
    echo "No prices available at this time";
}
else{
    ... show the price etc ...
}

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.