V
V
Vladislav Prubnyak2018-02-08 13:21:57
WordPress
Vladislav Prubnyak, 2018-02-08 13:21:57

How to change payment methods by hook in woocommerce cart?

Please tell me what is wrong

add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );
add_filter( 'woocommerce_available_payment_gateways' , 'unsetting_payment_gateway', 10, 1);

function wc_minimum_order_amount() {
  $limit_reached = false;
  // Задать переменную, чтобы указать минимальное значение заказа
  $minimum = 1000;	
    if ( WC()->cart->total < $minimum ) {
      function unsetting_payment_gateway( $available_gateways ) {
        // Здесь установить способ оплаты
        unset($available_gateways['cod']);
      }
    }
    return $available_gateways;
}

Required if the order amount is less than 1000, make the payment method "Pay on delivery" inactive or do not show
Thank you in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladislav Prubnyak, 2018-02-09
@Vaprubnyak

Problem solved thanks OKyJIucT
Working code:

add_action( 'woocommerce_checkout_process', 'wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart' , 'wc_minimum_order_amount' );

$limit_reached = false;

function wc_minimum_order_amount() 
{
  // Задать переменную, чтобы указать минимальное значение заказа
  $minimum = 1000;
  
  if ( WC()->cart->total < $minimum ) {
    $limit_reached = true;
    
  }
  return $limit_reached;
}

function unsetting_payment_gateways( $available_gateways ) 
{	
  $limit_reached = wc_minimum_order_amount();
  if ($limit_reached) {			
      // Здесь установить способ оплаты
      unset($available_gateways['cod']);
  }
  
  return $available_gateways;
}
add_action('woocommerce_available_payment_gateways', 'unsetting_payment_gateways');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question