After a Checkout using the Square Payment Gateway, the inventory stock is reduced in WooCommerce and synced with Square using background processing.
The stock is reduced in Woo using the woocommerce_checkout_order_processed hook and updated in Square, and woocommerce_update_product is used to pull the updated inventory back to Woo.
But when RazorPay is active, this sequence is reversed.
During Checkout, the stock in Woo is reduced but since woocommerce_update_product is triggered first, Woo Square fetches the unchanged stock from Square and resets it in Woo.
From the original issue:
Hello everyone,
I have investigated the behaviour between 5 payment gateways, in which some of them don't produce this issue.
Gateways with issue:
Klarna
Revolut
RazorPay
Gateways without issue:
Stripe
COD
Square itself
To understand the issue, it's important to understand how Woo Square syncs its inventory and the sequence as well.
Woo Square relies on the following 2 WooCommerce hooks to manage inventory:
woocommerce_checkout_order_processed
woocommerce_update_product
During Checkout, woocommerce_checkout_order_processed is triggered first which initiates a sync that sets the reduced stock in Square. After this, woocommerce_update_product is triggered which fetches the reduced stock from Square and updates it in Woo product.
This is the sequence which is followed by Square, COD and Stripe.
But for the gateways such as Klarna, Revolut and RazorPay, the sequence is reversed — woocommerce_update_product is triggered before woocommerce_checkout_order_processed
During Checkout through one of these gateways, the stock in Woo is reduced but since woocommerce_update_product is triggered first, Woo Square fetches the unchanged stock from Square and resets it in Woo.
This is why when you check stock in Woo immediately after Checkout using these gateways, you can see the stock reduced, but after a few seconds when woocommerce_update_product finishes, Woo product stock reverts back to the original count.
After a Checkout using the Square Payment Gateway, the inventory stock is reduced in WooCommerce and synced with Square using background processing. The stock is reduced in Woo using the
woocommerce_checkout_order_processed
hook and updated in Square, andwoocommerce_update_product
is used to pull the updated inventory back to Woo. But when RazorPay is active, this sequence is reversed. During Checkout, the stock in Woo is reduced but sincewoocommerce_update_product
is triggered first, Woo Square fetches the unchanged stock from Square and resets it in Woo.From the original issue:
Hello everyone,
I have investigated the behaviour between 5 payment gateways, in which some of them don't produce this issue.
Gateways with issue:
Gateways without issue:
To understand the issue, it's important to understand how Woo Square syncs its inventory and the sequence as well.
woocommerce_checkout_order_processed
woocommerce_update_product
woocommerce_checkout_order_processed
is triggered first which initiates a sync that sets the reduced stock in Square. After this,woocommerce_update_product
is triggered which fetches the reduced stock from Square and updates it in Woo product.woocommerce_update_product
is triggered beforewoocommerce_checkout_order_processed
woocommerce_update_product
is triggered first, Woo Square fetches the unchanged stock from Square and resets it in Woo.This is why when you check stock in Woo immediately after Checkout using these gateways, you can see the stock reduced, but after a few seconds when
woocommerce_update_product
finishes, Woo product stock reverts back to the original count.