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;
}
Last Update on:March 5th, 2023 at 5:19 pm