2

Is it possible to add cross sell products on the checkout page? How can we do that? Any help will be appreciated. Thank you.

1 Answer 1

5

You can show cross-sell products on checkout page by add below code to checkout_index_index.xml

app/design/frontend/YourVendorName/YourTheme/Magento_Checkout

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="checkout" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="content">
            <block class="Magento\Checkout\Block\Cart\Crosssell" name="checkout.cart.crosssell" template="Magento_Catalog::product/list/items.phtml" after="-">
                <arguments>
                    <argument name="type" xsi:type="string">crosssell</argument>
                </arguments>
                <block class="Magento\Catalog\Block\Product\ProductList\Item\Container" name="crosssell.product.addto" as="addto">
                    <block class="Magento\Catalog\Block\Product\ProductList\Item\AddTo\Compare"
                           name="crosssell.product.addto.compare" as="compare"
                           template="Magento_Catalog::product/list/addto/compare.phtml"/>
                </block>
            </block>
        </referenceBlock>
    </body>
</page>
4
  • How to get cross sell products pro-grammatically in cart page? Commented Nov 10, 2018 at 11:47
  • this worked, just for Magento 2.4 i had to put the file under app/design/frontend/YourVendorName/YourTheme/Magento_Checkout/layout
    – omerts
    Commented Aug 4, 2021 at 22:28
  • I've added the above code in my checkout_index_index.xml file but it's not working.. there is no block name as "content" so the above one is not a correct code to add the cross sell product in checkout page
    – senthil
    Commented Jun 17, 2022 at 12:58
  • (Magento 2.4.5) Need to add the view_model for this solution to work, so add this 2nd argument: <argument name="view_model" xsi:type="object">Magento\Catalog\ViewModel\Product\Listing\PreparePostData</argument> Otherwise Error: Call to a member function getPostData() on null in /var/www/html/vendor/magento/module-catalog/view/frontend/templates/product/list/items.phtml:266
    – Mike Dubs
    Commented Aug 6, 2023 at 17:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.