Created
March 20, 2015 13:17
-
-
Save romuloctba/b4eec7adc385f30b186d to your computer and use it in GitHub Desktop.
WooCommerce new order programatically (simpler, untested yet)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usefull reference: Class WC_Abstract_order with methods and stuff: http://docs.woothemes.com/wc-apidocs/class-WC_Abstract_Order.html