4

i am trying to remove a Crossell from cart page in my phtml file how i can do this

when i researched i found crosssell products are viewed in checkout_cart_index.xml file

as

<referenceContainer name="content">
            <block class="Magento\Checkout\Block\Cart" name="checkout.cart" template="Magento_Checkout::cart.phtml" cacheable="false">
                <container name="checkout.cart.items" as="with-items">
                    <block class="Magento\Checkout\Block\Cart\Crosssell" name="checkout.cart.crosssell" template="Magento_Catalog::product/list/items.phtml" after="-" ifconfig="checkout/cart/crosssell_enabled">
                    </block>
                </container>
            </block>
        </referenceContainer>

i have tried following code

$layout =$this->getLayout();
$parent  = $layout->getBlock('checkout.cart');
if ($parent) {
   $parent->unsetChild('checkout.cart.crosssell');
 }

i have tried each and every answer from stackexchange

i want to remove block on following condtion

if($sliderData->getSliderType()=='cross-sells')
        {
            $type = 'crosssell';
            $class = $type;
            $image = 'upsell_products_list';
            $sliderTitle = $sliderData->getSliderTitle();
            $sliderDescription= $sliderData->getSliderDescription();
            $items = $block->getCrossSellCollection($product);
            $exist = count($block->getCrossSellCollection($product));
            $limit = 4;
            $shuffle = 0;
            $showAddTo = true;
            $showCart = true;
            $templateType = null;
            $description = false;
            $canItemsAddToCart = false;
            $layout =$this->getLayout();
            $parent  = $layout->getBlock('checkout.cart');
            if ($parent) {
                $parent->unsetChild('checkout.cart.crosssell');
            }
3
  • you can set condition in phtml file – Rk Rathod Jun 21 '19 at 9:35
  • check my question again – Real Magento Man Jun 21 '19 at 9:40
  • Why not just use remove="true" in your layout xml? – Jaimin Sutariya Jun 21 '19 at 11:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.