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.

2 Answers 2


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();?>

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">

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.