I want to hide the "Zip/Postal Code" region in the summary Block in the cart page.I overwrote the block file LayoutProcessor.php. In that file, if I hid the following portion from the function process, then I would be able to hide the "Zip/Postal Code".

'postcode' => [
            'visible' => true,
            'formElement' => 'input',
            'label' => __('Zip/Postal Code'),
            'value' => null

I want to check the attributes of the products in the cart. If any of the products has the attribute value 'No', then hide the "Zip/Postal Code" and instead show an error message. How can I add the condition in LayoutProcessor.php to hide the same based on the attributes of the products on the cart.


Add the following lines in the function. The $cartData will provide you the products

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $productObject = $objectManager->create('Magento\Catalog\Model\Product');
    $cartObject = $objectManager->create('Magento\Checkout\Model\Cart');
    $cartData = $cartObject->getQuote()->getAllItems();

Then Please loop through the $cartData and use the following code in the loop

foreach ($cartData as $item) {
        $product = $productObject->load($item->getProduct()->getId());
        $attr = $product->getAttributeText('attribute_you_want') ;
        /*conditions u need*/

Add the 'if' condition to hide the part u need to.

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.