Magento 2: Add button next to “Shopping Cart” title
-
06-02-2021 - |
Question
When viewing my shopping cart there is an header "Shopping Cart", looks like this:
How can I add an button (or just a "a href link which has div inside it" would also be good enough) in that header part?
For example I would like to get "Continue shopping" which redirects to homepage when pressed.
In the end I want something like this:
Thank you very much!
Solution
Override vendor/magento/module-theme/view/frontend/templates/html/title.phtml file in your active theme and update it like below.
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
/**
* @var $block \Magento\Theme\Block\Html\Title
*/
$cssClass = $block->getCssClass() ? ' ' . $block->getCssClass() : '';
$title = '';
if (trim($block->getPageHeading())) {
$title = '<span class="base" data-ui-id="page-title-wrapper" ' . $block->getAddBaseAttribute() . '>'
. $block->escapeHtml($block->getPageHeading()) . '</span>';
}
?>
<?php if ($title): ?>
<div class="page-title-wrapper<?= /* @escapeNotVerified */ $cssClass ?>">
<h1 class="page-title"
<?php if ($block->getId()): ?> id="<?= /* @escapeNotVerified */ $block->getId() ?>" <?php endif; ?>
<?php if ($block->getAddBaseAttributeAria()): ?>
aria-labelledby="<?= /* @escapeNotVerified */ $block->getAddBaseAttributeAria() ?>"
<?php endif; ?>>
<?= /* @escapeNotVerified */ $title ?>
</h1>
<?= $block->getChildHtml() ?>
<?php if($block->escapeHtml($block->getPageHeading()) == "Shopping Cart") { ?><span><button>MyButton</button></span> <?php } ?>
</div>
<?php endif; ?>
Let me know if any further help needed.
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange