Home › Forums › WoodMart support forum › Duplicate orders are created. › Reply To: Duplicate orders are created.
March 10, 2024 at 10:31 pm
#547815
bitpublimedia
Participant
/**
* Prevent duplicate order
*/
add_filter('woocommerce_defer_transactional_emails', '__return_true' );
add_action( 'woocommerce_after_checkout_validation', 'forbid2orders', 10, 2 );
function forbid2orders( $fields, $errors ){
$c_user_email = $fields['billing_email'];
$c_transient_key = 'create_order_'.$c_user_email;
$create_order = true;
if(false === ($c_transient_results = get_transient($c_transient_key))){
$c_transient_results = $fields['billing_email'];
set_transient($c_transient_key, $c_transient_results, 3 * MINUTE_IN_SECONDS );
}else{
if($c_transient_results == $fields['billing_email']){
$errors->add( 'validation', 'An order has already been created. Please check your <a href="/my-account/orders/">Orders</a> or wait a few minutes to place a new one.' );
}
}
}
I am pasting the snippet here as it didn’t let me upload a php file as an attachment