Skip Navigation

[Resolved] In action 'woocommerce_order_status_completed', no custom fields added yet

This support ticket is created 5 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Tagged: 

This topic contains 3 replies, has 2 voices.

Last updated by catherineR-2 5 years, 1 month ago.

Assisted by: Waqar.

Author
Posts
#1208089

I'm hooking into action 'woocommerce_order_status_completed' with a priority of 9999 and even then, the custom fields I have added to the order are not yet in the postmeta table. In my function, I'm just dumping to error log the postmeta fields, and the custom fields I added to the order page and not in the postmeta table (though when I check in phpmyadmin they're there.) What priority # should I use to execute after Toolset has added the fields to postmeta?

#1208517

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Catherine,

Thank you for waiting, while I performed a few tests on my own website.

The way "woocommerce_order_status_completed" hook works it only gets triggered when an order's status is changed from "any other status" to "Completed".

But when an admin creates a new order from the admin area and sets "Completed" status directly, this hook ( woocommerce_order_status_completed ) is not triggered at that time.

This hook works if you've set a different status to the order while creating it and then that order is saved again, setting the order status to "Completed".

I hope this clarifies that this limitation comes from WooCommerce's own hook and not from WordPress or any other plugin like Toolset.

A simple workaround to make this code work is to make sure that a new order is created from the admin area, with initial status set to a different status like "Processing" and then setting it to "Completed".

Alternatively, you'll need to create a new function specifically for execution at the time of new order post's creation, using hooks like:
https://codex.wordpress.org/Plugin_API/Action_Reference/wp_insert_post
https://codex.wordpress.org/Plugin_API/Action_Reference/save_post

regards,
Waqar

#1208687

Hi Waqar,

Thanks for your response and assistance. The 'woocommerce_order_status_completed' does get fired on a new order. From my sample code I showed, I am dumping the order postmeta to the error log on that action, and it does get outputted when I enter a new order.

My method was working when I was using ACF plugin for custom fields, so I guess they hook in at a different point from Toolset to add custom fields. I'll try moving my logic to the save_post action and see if that works.

Thanks!

#1208697

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.