我正在使用此功能为我的客户创建新订单...
public function create_order( $user_id, $address, $product_id ) {
if ( ! $address ) return false;
$address = array(
'first_name' => $address->billing_first_name,
'last_name' => $address->billing_last_name,
'email' => $address->billing_email,
'phone' => $address->billing_phone,
'address_1' => $address->billing_address_1,
'city' => $address->billing_city,
'state' => $address->billing_state,
'postcode' => $address->billing_postcode,
'country' => $address->billing_country
);
$default_args = array(
'status' => 'wc-pending',
'customer_id' => $user_id,
);
// Now we create the order
$order = wc_create_order( $default_args );
$order->add_product( get_product( $product_id ), 1 ); // This is an existing SIMPLE product
// set default address to the created order
$order->set_address( $address, 'billing' );
//calculate total order price
$order->calculate_totals();
$order->update_status( "pending", 'Order Created Successfully And Payment is not completed', TRUE );
return $order;
}
这确实创建了一个新订单,但不计算运输成本...请参见下面的屏幕截图
我有根据用户帐单状态和总商品数量确定的统一费率运费。...如何像结帐时一样自动设置运费计算。