Limit Orders per Customer per Day
Blocks a customer from placing more than a set number of orders in 24 hours, matched by billing email, to stop card testing and reseller bots.
Opens WPIDE on
Code
$wpide_daily_orders = 3; // Orders allowed per email in 24 hours.
add_action( 'woocommerce_after_checkout_validation', function ( $data, $errors ) use ( $wpide_daily_orders ) {
$email = sanitize_email( (string) ( $data['billing_email'] ?? '' ) );
if ( ! is_email( $email ) || $errors->has_errors() ) {
return;
}
$recent = wc_get_orders( array(
'billing_email' => $email,
'date_created' => '>' . ( time() - DAY_IN_SECONDS ),
'status' => array( 'wc-pending', 'wc-processing', 'wc-on-hold', 'wc-completed' ),
'limit' => $wpide_daily_orders,
'return' => 'ids',
) );
if ( count( $recent ) >= $wpide_daily_orders ) {
$errors->add( 'validation', 'You have reached the daily order limit. Please contact us if you need to place another order today.' );
}
}, 20, 2 );
Notes
Failed and cancelled orders do not count, and orders shop managers create in the admin are not affected.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.