Woocommerce Single Use Coupon not updated on use

Ok this is my scenario, I have a single use coupon 12345, and two users A and B use the same coupon at same time. If User A has applies the coupon and is currently at the payment page, Woocommerce accepts the same coupon 12345 from user B and both transactions are succesfull.

Any way to prevent this?

Related posts

Leave a Reply

1 comment

  1. You can try this waiting for woocommerce to repair this bug :

    // 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();
    }