Last active
November 23, 2023 12:15
-
-
Save rwkyyy/2887a0899aba0457cf93c452a82ce61b to your computer and use it in GitHub Desktop.
Remove cash on delivery if any product in cart is on backorder - WooCommerce
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function remove_cod_if_backorder( $available_gateways ) { | |
if ( !is_array( $available_gateways ) ) return; | |
foreach ( WC()->cart->get_cart() as $cart_item ) { | |
$product = $cart_item['data']; | |
if ( $product && $product->is_on_backorder( $cart_item['quantity'] ) ) { | |
unset( $available_gateways['cod'] ); | |
break; | |
} | |
} | |
return $available_gateways; | |
} | |
add_filter( 'woocommerce_available_payment_gateways', 'remove_cod_if_backorder' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment