Question

I want to move Paypal express checkout button from the payment section to the top of the checkout page in Magento 2.

Was it helpful?

Solution

I have achieved by this way.

Custom/Module/view/frontend/layout/checkout_index_index.xml

<?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>
        <referenceContainer name="content">            
            <block class="Magento\Paypal\Block\Express\InContext\Minicart\SmartButton" name="checkout.right.logo" template="Custom_Module::express/in-context/shortcut/button.phtml" before="-">                
            </block>            
        </referenceContainer>        
    </body>
</page>

Custom/Module/view/frontend/templates/express/in-context/shortcut/button.phtml

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

/**
 * @var \Magento\Paypal\Block\Express\InContext\Minicart\SmartButton $block
 */
$widget = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonDecode($block->getJsInitParams());
$widgetConfig = $this->helper(\Magento\Framework\Json\Helper\Data::class)->jsonEncode($widget['Magento_Paypal/js/in-context/button']);
?>
<div data-mage-init='{"Magento_Paypal/js/in-context/button":<?= /* @noEscape */ $widgetConfig ?>}'
     class="paypal checkout paypal-logo paypal-express-in-context-mini-cart-container">
</div>
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top