Hiding payment method based on selected shipping method

josephraphael
Tourist
9 0 3

Hello,

 

I would like to use Shopify script API in order to hide a certain payment method based on the user's selection of the shipping method.

 

I would apperciaite any help.

BradKrane
Shopify Partner
42 4 8

From the API doc it doesn't appear possible as there is no indication in the Cart object of the selected shipping method and the Payment scripts only doesn't add any reference to shipping.

0 Likes
josephraphael
Tourist
9 0 3

@BradKrane I was able to do it through liquid and some javascript, it's pretty stable and working fine.

fullyfilmy
New Member
2 0 0

how to if they select paid order redirect directly to razor payment gateway or they select COD comeplete the order 

or maybe how o hide the payment gateway according to shippment selection

Ps i have shopify pluspayement gateway.png

 

0 Likes
PaulNewton
Shopify Partner
2571 136 454

@fullyfilmy a customers chosen shipping_rates ,or cart attributes are accessible in payment scripts so you would need to use javascript in checkout.liquid to hide/show payment methods

 

https://shopify.dev/docs/themes/liquid/reference/objects/checkout#checkout-shipping_method

https://shopify.dev/tutorials/develop-theme-layouts-best-practices

Problem Solved? ✔️Accept and ? Like the solution so you can help others.
Buy me a coffee ☕ paypal.me/paulnewton or donate to eff.org
Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com
0 Likes
Nestasia
Tourist
15 0 1

@PA I am trying to input the below in my checkout.liquid template - would you be able to help point out where I am getting this wrong ?

 

Input.shipping_method.each do |shipping_method|
            next unless shipping_method.title == "Prepaid Payment"
                     Output.payment_gateways = Input.payment_gateways.delete_if do |payment_gateway|
                     payment_gateway.name == "COD - Cash on Delivery"
             end
end
0 Likes