Title: Change order author
Last modified: August 27, 2019

---

# Change order author

 *  Resolved [snuffybg](https://wordpress.org/support/users/snuffybg/)
 * (@snuffybg)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/change-order-author/)
 * Hello,
    What would be the best approach to change the author of an order? By 
   default all orders are assigned to the admin.
 * Currently i’ve added
 *     ```
       add_post_type_support( 'product', 'author' );
        add_post_type_support( 'shop_order', 'author' );
       ```
   
 * I cant understand this hook “woocommerce_checkout_create_order” and how to update
   the author meta based on the product author.
    What i tried is:
 *     ```
       add_action('woocommerce_checkout_create_order', 'custom_set_order_author', 20, 2);
       function custom_set_order_author( $order, $data ) {
           $items = $order->get_items(); 
           foreach ( $items as $item ) {
               $product_id = wc_get_product($item->get_product_id());
               $author_id = get_post_field( 'post_author', $product_id );
           }
           $order_id = $order->get_order_number();
           update_post_meta( $order_id,'post_author', $author_id );
       }
       ```
   
 * I already restricted customer to add products only if they are from the same 
   author so it will have same author for order and product.
    -  This topic was modified 6 years, 10 months ago by [snuffybg](https://wordpress.org/support/users/snuffybg/).

Viewing 1 replies (of 1 total)

 *  Thread Starter [snuffybg](https://wordpress.org/support/users/snuffybg/)
 * (@snuffybg)
 * [6 years, 10 months ago](https://wordpress.org/support/topic/change-order-author/#post-11871928)
 * This is working for me
 *     ```
       add_action('woocommerce_checkout_update_order_meta', 'custom_set_order_author', 20, 2);
       function custom_set_order_author( $order_id, $data ) {
   
           $order = wc_get_order( $order_id );
           $items = $order->get_items(); 
           $product_id = reset($items)->get_product_id();
           $post_obj = get_post($product_id);
           $author_id = $post_obj->post_author;
           wp_update_post(array('ID' => $order_id, 'post_author' => $author_id));
       }
       ```
   
 * If you have any notes please share

Viewing 1 replies (of 1 total)

The topic ‘Change order author’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce/assets/icon.svg?rev=3234504)
 * [WooCommerce](https://wordpress.org/plugins/woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce/reviews/)

## Tags

 * [author](https://wordpress.org/support/topic-tag/author/)
 * [new order](https://wordpress.org/support/topic-tag/new-order/)
 * [order](https://wordpress.org/support/topic-tag/order/)
 * [product](https://wordpress.org/support/topic-tag/product/)

 * 1 reply
 * 1 participant
 * Last reply from: [snuffybg](https://wordpress.org/support/users/snuffybg/)
 * Last activity: [6 years, 10 months ago](https://wordpress.org/support/topic/change-order-author/#post-11871928)
 * Status: resolved