I'm creating a ReSTFUL way to initiate an order via WooCommerce, my code is as follows
function submitOrder($token, $productIDs, $shipping)
{
$order = wc_create_order();
$product_item_id = $order->add_product( wc_get_product( $productIDs[0]['productID'] ));
//wc_add_order_item_meta($product_item_id,"meta_key","meta_values");
$addressShipping = array(
'first_name' => $shipping['first_name'],
'last_name' => $shipping['last_name'],
'email' => $shipping['email'],
'phone' => $shipping['phone'],
'address_1' => $shipping['address']['street'],
'city' => $shipping['address']['city'],
'state' => $shipping['address']['state'],
'postcode' => $shipping['address']['postcode'],
'country' => 'AU');
$order->set_address( $addressShipping, 'shipping' );
$order->set_address( $addressShipping, 'billing' );
I've been reading the WooCommerce Docs and I have a rough understanding on how to retrieve a WC_Shipping
class.
However, to go through the Shipping Zones, work out if the minimum order has been reached, etc, seems tedious. Is there a method that already works out the best shipping Method (based on the content of the WC_Order
) then returns a WC_Shipping
class to attach to the WC_Order
?
I noticed that there is a calculate_shipping()
method, which takes on a package
Array. I couldn't find anything on this Array and what data is needed. Would this do the job?
Thanks.