Allow one basket item before clicking the order button or click the "Place an order" button.

I want to ban a place order if the cart item is more than two times by clicking the β€œProceed to checkout” or β€œSet an order” button by clicking in woocommerce. I do not want to check it for validation of the basket validation, please, can anyone help me?

+4
source share
2 answers

You can use the WooCommerce Min / Max Quantities extension to set the minimum and maximum quantities needed for validation.

or

functions.php "woocommerce_after_checkout_validation" $ordered array ,

add_action('woocommerce_after_checkout_validation', 'rei_after_checkout_validation');

    function rei_after_checkout_validation( $posted ) {

        // do all your logics here...

    }
+1
function custom_checkout_button_action(){
     global $woocommerce;
     $items = $woocommerce->cart->get_cart();
     $total = 0;
      foreach($items as $item => $values) { 
        $total = $values['quantity'];       
      }
      if($total>=2){
          ?>
          <a href="//your check out URL" onclick="return false"><?php  _e( 'Check On Out', 'woocommerce' ); ?></a>        
          <?php
      }
      else{
          ?>
          <a href="//your check out URL"><?php  _e( 'Check On Out', 'woocommerce' ); ?></a>           
          <?php
      }   
}
add_action('woocommerce_proceed_to_checkout', 'custom_checkout_button_action');

, HTML, , .

0

Source: https://habr.com/ru/post/1667524/


All Articles