wordpress - WooCommerce programmatically add order for a specific user -


i working on custom woocommerce plugin. in 1 of function want add order system/database wc_create_order().

the code beneath works fine, can't find way dedicate order specific user (so shows in backend , on accountpage of user).

(db field is: '_customer_user' ???)

my code:

// $productid, $userid, $price passed in function  $user = get_userdata($userid);  $address = array(         'first_name' => get_user_meta( $userid, "billing_first_name", true),         'last_name'  => get_user_meta( $userid, "billing_last_name", true),         '......' );  $order = wc_create_order();  $args['totals']['subtotal'] = $price; $args['totals']['total'] = $price;  $order->add_product( get_product( $productid ), 1, $args ); $order->set_address( $address, 'billing' ); $order->set_address( $address, 'shipping' ); $order->calculate_totals(); 

you can update_post_meta

update_post_meta( $order->id, '_customer_user', $userid ); 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -