Skip to content

Instantly share code, notes, and snippets.

@romuloctba
Created March 20, 2015 13:17
Show Gist options
  • Save romuloctba/b4eec7adc385f30b186d to your computer and use it in GitHub Desktop.
Save romuloctba/b4eec7adc385f30b186d to your computer and use it in GitHub Desktop.
WooCommerce new order programatically (simpler, untested yet)
<?php //from http://stackoverflow.com/a/26588393/1576978
$address = array(
'first_name' => 'Fresher',
'last_name' => 'StAcK OvErFloW',
'company' => 'stackoverflow',
'email' => '[email protected]',
'phone' => '777-777-777-777',
'address_1' => '31 Main Street',
'address_2' => '',
'city' => 'Chennai',
'state' => 'TN',
'postcode' => '12345',
'country' => 'IN'
);
$order = wc_create_order();
$order->add_product( get_product( '12' ), 2 ); //(get_product with id and next is for quantity)
$order->set_address( $address, 'billing' );
$order->set_address( $address, 'shipping' );
$order->calculate_totals();
@romuloctba
Copy link
Author

Usefull reference: Class WC_Abstract_order with methods and stuff: http://docs.woothemes.com/wc-apidocs/class-WC_Abstract_Order.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment