Thanks for the reply, But We can hide the gateways by the following codes:
// Disable Woocommerce payment methods based on product title containing 'SPECIFIC STRING'
add_filter( 'woocommerce_available_payment_gateways', 'wpsh_disable_gateways_based_on_product_title', 10, 1 );
function wpsh_disable_gateways_based_on_product_title( $gateways ) {
// Check if cart is initialized
if ( ! WC()->cart ) {
return $gateways;
}
// Loop through cart items
foreach ( WC()->cart->get_cart() as $cart_item ) {
$product = $cart_item['data'];
$product_title = $product->get_name();
// Check if the product title contains 'SPECIFIC STRING'
if ( stripos( $product_title, 'SPECIFIC STRING' ) !== false ) {
// If the condition is met, disable the payment gateway
if ( isset( $gateways['bacs'] ) ) {
unset( $gateways['bacs'] );
}
break;
}
}
return $gateways;
}
Also:
// Disable Woocommerce payment methods based on product description containing 'SPECIFIC STRING'
add_filter( 'woocommerce_available_payment_gateways', 'wpsh_disable_gateways_based_on_product_description', 10, 1 );
function wpsh_disable_gateways_based_on_product_description( $gateways ) {
// Check if cart is initialized
if ( ! WC()->cart ) {
return $gateways;
}
// Loop through cart items
foreach ( WC()->cart->get_cart() as $cart_item ) {
$product = $cart_item['data'];
$product_description = $product->get_description();
// Check if the product description contains 'SPECIFIC STRING'
if ( stripos( $product_description, 'SPECIFIC STRING' ) !== false ) {
// If the condition is met, disable the payment gateway
if ( isset( $gateways['bacs'] ) ) {
unset( $gateways['bacs'] );
}
break;
}
}
return $gateways;
}
Regards