简体   繁体   中英

Hiding an element by geolocation on Shopify Checkout page without inline script?

I'm trying to use an API call to IPstack in order to hide the express payment options for customers coming from Japan (JP). It worked a few times when testing via browser stack, but now my api call is getting the following consolve log error 'because it violates the following Content Security Policy directive: "script-src 'self' 'unsafe-inline' 'unsafe-eval' blob: cdn.shopify.com cdn.shopifycdn.net cdn.shopifycloud.com app.shopify.com'. Does anyone know any other way to hide elements by geolocation on the shopify checkout.liquid page?

<div class ="alt-payments">{{ alternative_payment_methods }}</div>
            <script>
              jQuery.ajax({
                url: 'https://api.ipstack.com/check?access_key=API_ACCESS_KEY&fields=country_code',
                dataType: 'jsonp',
                success: function(location) {
                    // If the visitor is browsing from JP.
                    if (location.country_code === 'JP') {
                    // display none express payments.
                    jQuery('.alt-payments').css('display','none');
                    }
                }
                } );
            </script>

I would use Shopify Scripts, since you're on Plus. Payments come after Shipping anyway. So you have the address BEFORE payments. Unless you are truly doing something weird. A normal Plus checkout would just check the address, then use a script to hide a payment method you don't like. That is the whole point of Plus.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM