Woocommerce 客户提交下订单时如何更改post_商业

Woocommerce 客户提交下订单时如何更改post_商业,woocommerce,Woocommerce,请帮助,当客户提交下订单时,woocommerce保存为post_author=1。(行政) 客户完成订单后,如何更改post_author=2? 请告知,谢谢也许这就是你需要的 // use action woocommerce_new_order or woocommerce_checkout_update_order_meta add_action( 'woocommerce_checkout_update_order_meta', 'modify_new_order', 10, 1 );

请帮助,当客户提交下订单时,woocommerce保存为post_author=1。(行政) 客户完成订单后,如何更改post_author=2?
请告知,谢谢

也许这就是你需要的

// use action woocommerce_new_order or woocommerce_checkout_update_order_meta
add_action( 'woocommerce_checkout_update_order_meta', 'modify_new_order', 10, 1 );

function modify_new_order( $order_id ) {
    $order = new WC_Order( $order_id );
    $my_post = [
       'ID'           => $order_id,
       'post_author'  => $order->user_id // user ID who created this post
    ];

   // Update the post into the database
   wp_update_post( $my_post );
}

谢谢这很有帮助。