Skip to content

Instantly share code, notes, and snippets.

@rwkyyy
Last active November 23, 2023 12:15
Show Gist options
  • Save rwkyyy/2887a0899aba0457cf93c452a82ce61b to your computer and use it in GitHub Desktop.
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
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