• Resolved Adrian Ghio

    (@aghio)


    I′m facing an issue:

    I can′t get the stock qty changes on variable product.

    (I mean: the variation ID2500 of product ID2499 changes his stock from 5 to 10. I should get the delta (more 5 units))

    I need to know the previous stock and the saved new stock when the client updates the product variation stock.

    I′ve tried using pre_post_update, woocommerce_before_save_product_variation hooks, save post, etc and I can′t get the change of stock.

    Please your help with it.

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Saif

    (@babylon1999)

    Hello @aghio,

    Thank you for reaching out!

    I understand you want to reduce the stock in increments of 5 instead of one per order, correct?

    You can check the Custom Stock Quantity Multiplier extension in the WooCommerce store. :?)

    I suggest you give it a try (we don’t offer trials but we have?a 30 day refund policy). If this extension turns out to be not what you were looking for,?please reach out to us via email?and we’ll be more than happy to help find alternatives.

    Let us know if you have any other questions.

    Thread Starter Adrian Ghio

    (@aghio)

    Thanks @babylon1999 , but not even close (maybe my english isn′t so god)

    I need to save the previous_stock (before save) and actual_stock (after save) of product or product_variation when the product is edited and saved.

    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @aghio

    The problem you’re encountering is related to tracking the change in stock quantity for a specific product variation. You need to know the previous and newly updated stock when a client modifies the product variation stock. Did I understand correctly?

    To save the previous_stock (before save) and actual_stock (after save) when a product or product_variation is edited and saved, you may need to use a combination of WooCommerce hooks and custom meta fields.

    You can try using the woocommerce_product_set_stock and woocommerce_variation_set_stock hooks. These hooks are triggered whenever the stock quantity of a product or product variation is changed.

    Alternatively, you can use the woocommerce_product_data_store_creating hook, which is triggered before a product is saved. In the function associated with this hook, you can retrieve the current stock quantity using $product->get_stock_quantity(), and then save it as a custom meta value for that product.

    Next, you can use the woocommerce_product_object_updated_props hook, which is triggered after a product is saved. In the function associated with this hook, you can retrieve the new stock quantity using the same $product->get_stock_quantity() method, and save it as another custom meta value.

    I hope this helps! If you have any further questions, please, do not hesitate to ask.

    Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Manage stock change on order or resposition’ is closed to new replies.