When updating my WooCommerce product variation stock via the WooCommerce REST API url:
https://url.com/wp-json/wc/v3/products/2982/variations/2989
And posting:
{
"stock_quantity": 145
}
It works fine and updates the stock level to 145
. The value before updating it was 25
. How can I receive this value in my action beneath:
add_action( 'woocommerce_rest_insert_product_variation_object', 'capture_previous_stock_quantity', 10, 3 );
function capture_previous_stock_quantity($variation, $request, $creating) {
$current_stock_qty = $variation->get_stock_quantity();
$headers[] = 'From: MyMail <[email protected]>';
$mailSubject = 'Test mail API';
$mailContent .= '<p>The current stock quantity is: '.$current_stock_qty.'</p>';
wp_mail( '[email protected]', $mailSubject, $mailContent, $headers );
}
This returns the value 145
inside $current_stock_qty
. I want the old stock level.
In the first try I had it in the action woocommerce_update_product
but there the value was already updated so I thought I could get the value correct inside the action mentioned above.
But it didn’t work out. Someone knowing how to help me?