On the shopping cart page, there are a proceed to checkout button display after order summary. I want to display also before the shopping cart grid.
How to display it?
Any help would be appreciated.
Thanks.
Use this below code for display button on top of grid on shopping cart page :
app/code/{Vendor}/{Module}/view/frontend/layout/checkout_cart_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="content">
<block class="Magento\Checkout\Block\Onepage\Link" name="checkout.cart.methods.onepage.top" template="Vendor_Module::onepage/link_top.phtml" before="checkout.cart" />
</referenceContainer>
</body>
</page>
app/code/{Vendor}/{Module}/view/frontend/templates/onepage/link_top.phtml
<?php
/** @var $block \Magento\Checkout\Block\Onepage\Link */
?>
<?php if ($block->isPossibleOnepageCheckout()) :?>
<button type="button"
data-role="proceed-to-checkout"
title="<?= $block->escapeHtmlAttr(__('Proceed to Checkout Top')) ?>"
data-mage-init='{
"Magento_Checkout/js/proceed-to-checkout":{
"checkoutUrl":"<?= $block->escapeJs($block->escapeUrl($block->getCheckoutUrl())) ?>"
}
}'
class="action primary checkout<?= ($block->isDisabled()) ? ' disabled' : '' ?>"
<?php if ($block->isDisabled()) :?>
disabled="disabled"
<?php endif; ?>>
<span><?= $block->escapeHtml(__('Proceed to Checkout Top')) ?></span>
</button>
<?php endif; ?>
Clean cache and check it.
Create checkout_cart_index.xml
at
app/code/{Vendor}/{Module}/view/frontend/layout/checkout_cart_index.xml
==========OR==========
app/design/frontend/{Package}/{theme}/layout/checkout_cart_index.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="cart.summary">
<block class="Magento\Checkout\Block\Onepage\Link" name="checkout.cart.methods.onepage.top" template="{Vendor}_{Module}::onepage/link_upper.phtml" before="-" />
</referenceContainer>
</body>
</page>
Create link_upper.phtml
at
app/code/{Vendor}/{Module}/view/frontend/templates/onepage/link_upper.phtml
==========OR=========
app/design/frontend/{Package}/{theme}/templates/onepage/link_upper.phtml
<?php
/** @var $block \Magento\Checkout\Block\Onepage\Link */
?>
<?php if ($block->isPossibleOnepageCheckout()) :?>
<button type="button"
data-role="proceed-to-checkout"
title="<?= $block->escapeHtmlAttr(__('Proceed to Checkout Top')) ?>"
data-mage-init='{
"Magento_Checkout/js/proceed-to-checkout":{
"checkoutUrl":"<?= $block->escapeJs($block->escapeUrl($block->getCheckoutUrl())) ?>"
}
}'
class="action primary checkout<?= ($block->isDisabled()) ? ' disabled' : '' ?>"
<?php if ($block->isDisabled()) :?>
disabled="disabled"
<?php endif; ?>>
<span><?= $block->escapeHtml(__('Proceed to Checkout Top')) ?></span>
</button>
<?php endif?>
Note: You may need to adjust design of upper checkout button
Hope above will help!