I need to add direct paypal express checkout buttons of enable payment methods in phtml file. I want to use them under custom layout section on cart page.


Here I am answering, How I get resolved this issue?

I created a link in .phtml file for Paypal Express:

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$storeManager = $objectManager->get('\Magento\Store\Model\StoreManagerInterface');
$baseurl = $storeManager->getStore()->getBaseUrl();
$paypalexpress = $baseurl.'paypal/express/start/button/1/';
<div id="button">
    <a href="<?php echo $paypalexpress; ?>">
    <img id="btnPayPal" src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif">

We can show paypal buttons in phtml file using call createBlock() as following:-

1] For show default paypal button

<?php echo $block->getLayout()->createBlock('Magento\Paypal\Block\Express\Shortcut')->setTemplate('express/shortcut.phtml')->toHtml();?>

2] For show in-context smart paypal button

<?php echo $block->getLayout()->createBlock('Magento\Paypal\Block\Express\InContext\Minicart\SmartButton')->setTemplate('express/in-context/shortcut/button.phtml')->toHtml();?>

Your Answer

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

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