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?
Leave a Reply
You must be registered and logged in to post a comment.