1

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'
        }
    }
};
| improve this question | | | | |
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.

| improve this answer | | | | |
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>
| improve this answer | | | | |
0

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

thank you

| improve this answer | | | | |

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.