Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- global $user;
- $product_ids = array(2);
- $order = commerce_order_new ( $user->uid , 'pending' );
- // Save the order so its ID is assigned.
- commerce_order_save ( $order );
- $order_wrapper = entity_metadata_wrapper ( 'commerce_order' , $order );
- //add products to order by ids array
- foreach ( $product_ids as $product_id ) {
- $product = commerce_product_load ( $product_id );
- // Create a line item with quantity 1 and this product.
- $line_item = commerce_product_line_item_new ( $product , 1 , $order->order_id );
- // Save the line item to get its ID.
- commerce_line_item_save ( $line_item );
- // Add the line item to the order using the wrapper.
- $order_wrapper->commerce_line_items[ ] = $line_item;
- }
- $profile_object = array (
- 'und' => array ( array ( 'profile_id' => 1 , ) , ) , );
- $order->commerce_customer_billing = $profile_object;
- // Save the order.
- commerce_order_save ( $order );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement