Add custom meta data after Payment confirmation in WooCommerce

纵然是瞬间 提交于 2019-12-04 19:23:59

You should better use dedicated woocommerce_payment_complete action hook this way:

add_action('woocommerce_payment_complete', 'custom_update_order_meta', 20, 1 );
function custom_update_order_meta( $order_id ) {
     update_post_meta( $order_id, 'My Field', 'test');
}

Code goes in function.php file of the active child theme (or active theme).

This should works.


For A plugin you will need to add this first in the __construct() function:

add_action('woocommerce_payment_complete', array( $this 'custom_update_order_meta'), 20, 1 );

And then something like:

public function custom_update_order_meta( $order_id ) {
     update_post_meta( $order_id, 'My Field', 'test');
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!