我想(以编程方式)创建订阅产品的订单。我从这个问题中找到了代码:Programmatically create new order in Woocommerce,我用它来尝试使其工作。
我无法使其与“简单订阅”和“简单产品”一起工作。
function create_vip_order() {
global $woocommerce;
$product_id = 123;
$address = array(
'first_name' => '111Joe',
'last_name' => 'Conlin',
'company' => 'Speed Society',
'email' => 'joe@testing.com',
'phone' => '760-555-1212',
'address_1' => '123 Main st.',
'address_2' => '104',
'city' => 'San Diego',
'state' => 'Ca',
'postcode' => '92121',
'country' => 'US'
);
// Now we create the order
$order = wc_create_order();
// The add_product() function below is located in /plugins/woocommerce/includes/abstracts/abstract_wc_order.php
$order->add_product( get_product( $product_id ), …Run Code Online (Sandbox Code Playgroud)