Skip to content
Advertisement

Add a custom meta field value to WooCommerce order if status changes to custom status

I have searched all over the internet. What I’m looking for is to create a custom woocommerce order field which will be automatically added to the order when order status changes to wc-kurzuhradena which the custom order status, with the value of current month and year. Example value: May 2021

So far I have this code which adds a custom field but I need to find a solution for a date when this status has been updated.

JavaScript

enter image description here

Thank you in advance for help.

Advertisement

Answer

For a custom order status you can use woocommerce_order_status_{$status_transition[to]} composite action hook, where you will replace {$status_transition[to]} by the custom status slug.

So you get:

JavaScript

To allow this only once, when changing to custom order status, use:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement