Skip to content

Instantly share code, notes, and snippets.

@WillBrubaker
Created March 29, 2021 04:30
Show Gist options
  • Save WillBrubaker/a612a91aaf83e42c16b97275d26cc09a to your computer and use it in GitHub Desktop.
Save WillBrubaker/a612a91aaf83e42c16b97275d26cc09a to your computer and use it in GitHub Desktop.
Conditionally hide shipping methods if payment request button is used for payment
// not sure what to do with this code snippet? See https://www.thathandsomebeardedguy.com/what-do-i-do-with-these-code-snippets/
// BTC Donations to: bc1qc2s60yct2aqza4r7ryweheepd8xa8wqpfgdhg3
//hook into wc_ajax_wc_stripe_get_shipping_options
add_action( 'wc_ajax_wc_stripe_get_shipping_options', 'handsome_bearded_guy_filter_shipping_methods' );
function handsome_bearded_guy_filter_shipping_methods() {
//hook into woocommerce_shipping_methods
add_filter( 'woocommerce_shipping_methods', 'handsome_bearded_guy_remove_shipping_methods' );
}
function handsome_bearded_guy_remove_shipping_methods( $shipping_methods ) {
unset( $shipping_methods['free_shipping'] );//remove Free Shipping
return $shipping_methods;
}
@vncnt-mb
Copy link

Doesn't work with WooCommerce 7.7.0 & WC Stripe 7.4.0

Adding a priority lower than 10 to the add_action line allows to reintegrate in the Stripe flow

add_action( 'wc_ajax_wc_stripe_get_shipping_options', 'handsome_bearded_guy_filter_shipping_methods', 1 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment