WooCommerce Order limit by Customer

 add_filter( 'woocommerce_add_to_cart_validation', 'ab_limit_one_per_order', 10, 2 );
 function ab_limit_one_per_order( $passed_validation, $user_id ) {

   $customer = new WC_Customer( $user_id );
   $order = $customer->get_order_count();

  if ( $order < 2) {
      wc_add_notice( __( 'This product cannot be purchased with other products. You have completed maximum number of order', 'woocommerce' ), 'error' );
     return false;
  }

  return $passed_validation;
 }

Leave a Reply

Your email address will not be published.