Home Assign the user ID to an order created programmatically in Woocommerce 3
Reply: 0

Assign the user ID to an order created programmatically in Woocommerce 3

user1991
1#
user1991 Published in May 27, 2018, 3:33 am

I’m using Woocommerce to manage my products on Wordpress, but the user pay through a 3rd party service.

I’m trying to create new order manually, and assign it to the current user.The order is indeed created and logged but the following code only log the item and the time, no details of the user:

  global $woocommerce;

  $address = array(
      'first_name' => $_GET['FirstName'],
      'last_name'  => $_GET['LastName'],
      'company'    => $_GET['CompanyName'],
      'email'      => $_GET['EmailAddress'],
      'phone'      => $_GET['MobilePhoneNumber'],
      'address_1'  => '',
      'address_2'  => '',
      'city'       => '',
      'state'      => '',
      'postcode'   => '',
      'country'    => $_GET['countryCode']
  );

  $order = wc_create_order();

  foreach ($woocommerce->cart->get_cart() as $cart_item_key => $values) {
            $item_id = $order->add_product(
                    $values['data'], $values['quantity'], array(
                'variation' => $values['variation'],
                'totals' => array(
                    'subtotal' => $values['line_subtotal'],
                    'subtotal_tax' => $values['line_subtotal_tax'],
                    'total' => $values['line_total'],
                    'tax' => $values['line_tax'],
                    'tax_data' => $values['line_tax_data'] // Since 2.2
                )
                    )
            );
        }
  $order->set_address( $address, 'billing' );
  //
  $order->calculate_totals();
  $order->update_status("Completed", 'Imported order', TRUE);  
$order->save();

The admin can see what was ordered (under woocommerce->orders) but not by whom, and the user can’t see his orders at all.

I've uploaded the website to a temporary domain so you guys can see: https://360transformations.000webhostapp.com/?page_id=446

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.31046 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO