V
V
Vladislav Prubnyak2018-02-09 10:37:36
WordPress
Vladislav Prubnyak, 2018-02-09 10:37:36

Why is the inscription in the checkout on woocommerce coming out 2 times instead of once?

Wrote the following code to hide the payment method at checkout in woocommerce

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) {
      // Задать переменную, чтобы указать минимальное значение заказа
      $minimum = 1000;
      // Здесь установить способ оплаты
      unset($available_gateways['cod']);
      wc_print_notice( 
                sprintf( 'Для оплаты заказа при получении ваша сумма заказа должна быть более %s Сейчас сумма вашего заказа %s. рублей' , 
                    wc_price( $minimum ), 
                    wc_price( WC()->cart->total )
                ), 'error' 
            );
  }
  
  return $available_gateways;
}
add_action('woocommerce_available_payment_gateways', 'unsetting_payment_gateways');

But the inscription "To pay for the order upon receipt, your order amount must be ..." is displayed 2 times instead of one
5a7d4aa90c323991200520.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladislav Prubnyak, 2018-02-12
@Vaprubnyak

I solved the problem by moving wc_print_notice to another hook.
woocommerce_available_payment_gateways in woo is called twice

A
Andrey Kotosin, 2018-02-09
@av_kotosin

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

Try to add else{ $limit_reached = false; }
but it's not accurate))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question