Ocultar forma de pago según producto el WooCommere

PHOTO EMBED

Wed Jun 29 2022 06:48:00 GMT+0000 (Coordinated Universal Time)

Saved by @edujca

//https://www.esthersola.com/ocultar-forma-de-pago-en-woocommerce-segun-productos/

//Hide payment method according to cart products

add_filter( 'woocommerce_available_payment_gateways', 'esl_payment_gateway_disable_by_cat' );


function esl_payment_gateway_disable_by_cat( $available_gateways) {

  if ( is_admin() && ! defined( 'DOING_AJAX' ) )
        return;
  
    global $woocommerce; 
 
    $bool = false;
	
    foreach ( WC()->cart->get_cart() as $cart_item_key => $cart_item ) {
	 
        if ( has_term( 'accessories', 'product_cat', $cart_item['product_id'] ) )    $bool = true;
 
    } 
	
    if ($bool) 
	{
	    unset(  $available_gateways['cheque'] ) ;
      
	}
 
	return $available_gateways;  
content_copyCOPY