Woocommerce single use coupon does not update on use
Ok, this is my scenario, I have one 12345 coupon and two users A and B use the same coupon at the same time. If User A applies the coupon and is currently on the checkout page, Woocommerce accepts the same 12345 coupon from User B and both transactions are successful.
How can you prevent this?
+3
source to share
1 answer
You can try this while waiting for woocommerce to fix this error:
// Hook after order creation and before going to payment page
add_action( 'woocommerce_checkout_order_processed' , 'increase_immediately_coupon', 10, 2);
function increase_immediately_coupon( $order_id, $received ){
$order = new WC_Order( $order_id );
$order->increase_coupon_usage_counts();
}
// Hook if gateway send and on-hold status
add_action( 'woocommerce_order_status_on-hold' , 'decrease_immediately_coupon', 10, 1);
function decrease_immediately_coupon( $order_id ){
$order = new WC_Order( $order_id );
$order->decrease_coupon_usage_counts();
}
0
source to share