2

We don’t want to make a call out to PayPal (https://www.paypalobjects.com/api/checkout.js) file when loading the homepage. We should only be making calls to PayPal on the cart page and checkout.

Module Name: Magento_Paypal

File Path: vendor/magento/module-paypal/view/frontend/requirejs-config.js

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

var config = {
    map: {
        '*': {
            orderReview: 'Magento_Paypal/order-review',
            paypalCheckout: 'Magento_Paypal/js/paypal-checkout'
        }
    },
    paths: {
        paypalInContextExpressCheckout: 'https://www.paypalobjects.com/api/checkout'
    },
    shim: {
        paypalInContextExpressCheckout: {
            exports: 'paypal'
        }
    }
};
1

You could try overwriting that Require JS file so it only loads on the pages you wish. * means load regardless of element, you can replace with a selector or selectors meaning the script will only load if those selectors are present.

This may work:

var config = {
    map: {
        '.checkout-index-index, .checkout-cart-index': {
            orderReview: 'Magento_Paypal/order-review',
            paypalCheckout: 'Magento_Paypal/js/paypal-checkout'
        }
    },
    paths: {
        paypalInContextExpressCheckout: 'https://www.paypalobjects.com/api/checkout'
    },
    shim: {
        paypalInContextExpressCheckout: {
            exports: 'paypal'
        }
    }
};

I say may because I haven't tried this with multiple selectors. If it doesn't support multiple selectors you could add it twice with a different selector each time.

0

I have found a solution with one of my co-developer followed below step.

app/design/frontend/Vendor/Theme/Magento_Theme/layout/cms_index_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
   <body>
         <referenceBlock name="paypal.express-in-context.component" remove="true" />
   </body>
</page>
0

you can insert this directly via magento admin interface in the layout update xml field. works fine for me.

thank you

0

Rest of the solutions did not work for me on Magento 2.3.4 and ended up with website not loading.

Had to set the Enable In-Context Checkout Experience setting to NO

Setting found in Stores > configuration > Sales > Payment methods > Paypal Express Checkout > Configure

0

A slight correction to Nagaraju's code: Tested and verified on Magento 2.3.x and 2.4

app/design/frontend/Vendor/Theme/Magento_Theme/layout/cms_index_index.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceContainer name="content">
               <referenceBlock name="paypal.express-in-context.component" remove="true" />
        </referenceContainer>
    </body>
</page>

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.