This document contains code to conditionally disable payment gateways in WooCommerce based on products in the cart. It includes a function to check if a given product ID is in the cart, and a function that removes a specific payment gateway if those products are in the cart. The payment gateway ID to disable is hardcoded, and the products that trigger the disable are configured via an array of product IDs.
This document contains code to conditionally disable payment gateways in WooCommerce based on products in the cart. It includes a function to check if a given product ID is in the cart, and a function that removes a specific payment gateway if those products are in the cart. The payment gateway ID to disable is hardcoded, and the products that trigger the disable are configured via an array of product IDs.
This document contains code to conditionally disable payment gateways in WooCommerce based on products in the cart. It includes a function to check if a given product ID is in the cart, and a function that removes a specific payment gateway if those products are in the cart. The payment gateway ID to disable is hardcoded, and the products that trigger the disable are configured via an array of product IDs.
//Primero comprobamos si el producto esta disponible o no en el carrito.
function is_product_in_cart( $prodids ){
$product_in_cart = false; foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) { $product = $cart_item['data']; if ( in_array( $product->id, $prodids ) ) { $product_in_cart = true; } } return $product_in_cart; } // Luego ya desactivamos la pasarela que queramos por ID de producto. Cambia los números de ID en el array $prodids function payment_gateway_disable_product( $available_gateways ) { global $woocommerce; //print_r( $available_gateways ); $prodids=array(12142,12136); if ( isset( $available_gateways['wc_pickup_store'] ) && is_product_in_cart( $prodids ) ) { unset( $available_gateways['wc_pickup_store'] ); }