click "checkout with paypal" in magento to open new window

click "checkout with paypal" in magento to open new window

September 25, 2026 · Illustrated author avatarBy Stefan Bogdanescu
click "checkout with paypal" in magento to open new window

Opening PayPal in a New Window During Checkout in Magento

As a senior developer specializing in e-commerce platforms like Magento, I often encounter questions about customizing the checkout process to meet specific business requirements. One of the most common issues is ensuring that the PayPal payment gateway opens in a new window or tab when the “Checkout with PayPal” button is clicked.

In this post, I’ll guide you through the process of achieving this without modifying core Magento files and provide practical examples for Magento 1.4+ versions.

Understanding the Problem: Why Can’t PayPal Open in an iframe?

Before we dive into the solution, it’s essential to understand why PayPal can’t open within aMagento iframe. Security restrictions prevent sensitive transactions like payments from being embedded within other applications or websites due to potential security risks and compliance issues with PCI standards.

Identifying the Relevant Files

To make PayPal open in a new window when clicked from your Magento store, we need to locate the relevant files that handle the “Checkout with PayPal” button action. In Magento 1.4+, you can find these files within the app\code\core\Mage\Paypal directory.

However, editing core files is generally discouraged as it may cause compatibility issues during updates and makes customizations harder to maintain. Instead, we’ll focus on extending or overriding the relevant controllers or blocks using Magento’s extension mechanism.

Extending the PayPal Express Shortcut Block

You mentioned finding a line of code in app\code\core\Mage\Paypal\Block\Express\Shortcut.php that defines the starting action for PayPal Express checkout. This file is part of the core Magento files, and editing it directly isn’t recommended.

Instead, we can create an extension to override this block’s behavior without modifying the original file. Here’s how you can achieve this:

  1. Create a new directory structure under app\code\local:
app/code/local/YourCompany/PaypalExpressCheckout/
  1. Inside the PaypalExpressCheckout directory, create two subdirectories: Block and etc.

  2. In the Block directory, create a copy of the core Magento file app\code\core\Mage\Paypal\Block\Express\Shortcut.php and name it Shortcut.php.

  3. Open your new Shortcut.php file and locate the protected variable $_startAction. It currently points to 'paypal/express/start'.

  4. To open PayPal in a new window, we’ll need to add JavaScript code that triggers when the PayPal button is clicked. However, since Magento uses an AJAX-based checkout process, simply adding a target="_blank" attribute won’t work.

  5. Instead, we can use jQuery or native JavaScript to intercept the click event on the PayPal button and force it to open in a new window. Here’s an example using jQuery:

require(['jquery'], function ($) {
    $(document).ready(function () {
        $('.paypal-button').on('click', function (event) {
            var href = $(this).attr('href');
            window.open(href, '_blank');
            event.preventDefault();
        });
    });
});
  1. To load this JavaScript file, we need to add it to the checkout page layout. Create a new XML file named checkout.xml inside the etc directory of your extension:
<?xml version="1.0"?>
<layout version="1.0">
  <checkout_index_index translate="label">
    <reference name="head">
      <action method="addJs">
        <script>YourCompany_PaypalExpressCheckout::js/jquery.js</script>
      </action>
    </reference>
  </checkout_index_index>
</layout>
  1. Make sure to create the js directory inside your extension path (app\code\local\YourCompany\PaypalExpressCheckout) and place your custom JavaScript file containing the code from step 6.

  2. Finally, you need to configure Magento to use your extension instead of the core PayPal Express checkout block. Update the config.xml file located in the etc directory of your extension:

<config>
    <modules>
        <YourCompany_PaypalExpressCheckout>
            <version>1.0</version>
        </YourCompany_PaypalExpressCheckout>
    </modules>
    <global>
        <blocks>
            <paypal>
                <rewrite>
                    <express_shortcut>YourCompany_PaypalExpressCheckout_Block_Shortcut</express_shortcut>
                </rewrite>
            </paypal>
        </blocks>
    </global>
</config>

Conclusion

Opening PayPal in a new window during the checkout process requires a combination of Magento extension development and custom JavaScript manipulation. By following this guide, you can create an extension that overrides the core PayPal Express Shortcut block without modifying any core files.

Remember to clean your cache after making these changes using the command php shell/indexer.php reindexall or through the Magento admin interface.

For more advanced customizations and best practices in Magento development, feel free to explore our Magento Development Services at Laravel Company. Our experienced team specializes in creating secure, scalable, and optimized Magento solutions tailored to your business needs.

Magento 1 Checkout Security API

Our network