WooCommerce, Remote Work & Other Fancy Stuff

Just another WordPress site

Hide Shipping Methods – Payment Request

March 29, 2021 by Will Leave a Comment

Please consider leaving a donation if you appreciate this information. Lightning network now available

It’s possible to conditionally remove shipping methods on the checkout page and there are several examples of how this can be done with code. Some of these examples can be seen here: https://docs.woocommerce.com/document/hide-other-shipping-methods-when-free-shipping-is-available/

However, what if we want to hide those shipping methods only if the purchase is done via a WooCommerce Stripe provided payment request button, Google Pay, Apple Pay, et. al.?

The WooCommerce Stripe payment gateway fires an AJAX action when it retrieves the available shipping methods. One can hook into this same action and on a callback to that, hook into an appropriate WooCommerce filter hook. The examples linked seem to favor filtering woocommerce_package_rates which is fine, but I’m lazy and that’s too much work. For my purposes, the woocommerce_shipping_methods filter is much more efficient.

Suppose I wanted to remove Free Shipping as an available shipping method if a customer is using the payment request button to pay. In code, that might look similar to:

Not sure what to do with code snippets? See What Do I Do With These Code Snippets?

Please consider leaving a donation if you appreciate this information. Lightning network now available

Filed Under: Stripe, WooCommerce Tagged With: apple-pay, google-pay, payment-request-button, snippet, snippets

Leave a Reply Cancel reply

You must be registered and logged in to post a comment.

© 2025 ยท WooCommerce, Remote Work & Other Fancy Stuff · Epstein didn't kill himself

We use cookies to ensure that we give you the best experience on our website. Continued use of this site is interpreted as your acceptance of our cookie policy.OkSee Our Cookie Policy