Hiding a gateway based on Specific product
-
Hi there, I think this option may be useful:
- Hide Gateways based on specific product ID(s)
Here is the CODE:
// Disable Woocommerce payment methods based on specific product ID in the cart
add_filter( 'woocommerce_available_payment_gateways', 'wpsh_disable_gateways_based_on_product_id', 10, 1 );
function wpsh_disable_gateways_based_on_product_id( $gateways ) {
// Check if cart is initialized
if ( ! WC()->cart ) {
return $gateways;
}
// Loop through cart items
foreach ( WC()->cart->get_cart() as $cart_item ) {
$product_id = $cart_item['product_id'];
// Check if the product ID is 145
if ( $product_id == 145 ) {
// If the condition is met, disable the payment gateway
if ( isset( $gateways['bacs'] ) ) {
unset( $gateways['bacs'] );
}
break;
}
}
return $gateways;
}Refards
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- You must be logged in to reply to this topic.