Can anyone tell me which action precedes the woocommerce_save_product_variation
action hook?
I’m trying to save old price and quantity before updating product variation
Can anyone tell me which action precedes the woocommerce_save_product_variation
action hook?
I’m trying to save old price and quantity before updating product variation
3
Answers
I solved with
woocommerce_variation_header
.This hook will be activated for each product variation. Therefore, you need to have a private class-level associative array, where you will store (for you) important information from product (variation), e.g. price, stock quantity, etc.
After that, save that array in db, ie. wp_options, with a specific name.
When you call
woocommerce_save_product_variation
, then also call array that you already saved for same variation fromwp_options
and finally then compare the data.That’s what I needed but a detour and reason for this approach is that I had to stay on the same old version of WooCommerce.
Thank you all for participating!
In meta-boxes/class-wc-meta-box-product-data.php line 530-541 you can find
So
woocommerce_admin_process_variation_object
action precedeswoocommerce_save_product_variation
Use
woocommerce_admin_process_variation_object
To find this kind of hook you can look woocommerce source files.
For example for this: I search the
woocommerce_save_product_variation
on http://hookr.io/. I saw that this hook was called inclass-wc-meta-box-product-data.php
. Then I take a look to this file and I findwoocommerce_admin_process_variation_object
hook who are called just before$variation->save();
Take a look here:
https://github.com/woocommerce/woocommerce/blob/ac9f83d7724b889a1740d651eb4cd8ac5bb5b4f2/includes/admin/meta-boxes/class-wc-meta-box-product-data.php#L537