Currently, I am customising checkout procedure, and I need to create order using code. I tried to use following code to create an order, but I cannot put variation_id
into product object. Assuming that I already know product_id
and variation_id
.
$my_order = wc_create_order(array('status'=>'processing','customer_id'=>$customer_id));
$my_product=new WC_Product($product_id);
$my_product->variation_id=$variation_id;
$my_order->add_product( $my_product, 1);
$order->set_address( $address, 'billing' );
$order->set_address( $address, 'shipping' );
$order->calculate_totals();
Anyone knows how to add $variation_id
into $my_product
?