Re: Standard Shopify App - show/hide payment methods

Standard Shopify App - show/hide payment methods

blackjam
Shopify Partner
10 0 1

Hi Everyone,

I have been able to setup a custom private app to inject script to a Shopify page. I can attach this using a script tag but this does not flow through to checkout. I understand that changes to the checkout page is heavily restricted but there are 3rd party apps that does this so it must be possible.

 

Specifically, I want my private app to be able to show/hide payment methods based on a set criteria.

 

Is this a possibility? We really need to get this working.

 

This is the sort of code I received from the web using c# and ASP .NET Core is below:

 

 

    public async Task<IActionResult> HidePaymentMethod(string checkoutId, string paymentMethodId)
    {
      // Fetch access token and Shopify API base URL from app settings
      var shopifyApiBaseUrl = _configuration["Shopify:ApiBaseUrl"];
      var accessToken = _configuration["Shopify:AccessToken"];

      var service = new ShopifyPaymentMethodsService(shopifyApiBaseUrl, accessToken);
      await service.HidePaymentMethod(checkoutId, paymentMethodId);

      return RedirectToAction("Index", "Checkout");
    }

 

 

We would really appreciate a solution on this.

Thanks - James

 

 

 

Reply 1 (1)

AlexHeard
Shopify Partner
64 0 1

In 2024, you really don't want to use Script tag to hide/show payment methods. There are better solutions available now. You can show/hide payment methods based on specific criteria using the PayRules: Hide Payment Methods app. Here's how you can do it:

 

  1. Choose the payment methods like Stripe, PayPal etc from the "Select payment methods" field.
  2. Apply the conditions (product, cart total etc).

scripttag.png

 

This will allow you to control the visibility of payment methods based on your criteria.