问题出在您的动作挂钩上。使用以下钩子:
add_action('woocommerce_checkout_process', 'create_vip_order');function create_vip_order() { global $woocommerce; $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', 'postpre' => '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('275962'), 1); // This is an existing SIMPLE product $order->set_address( $address, 'billing' ); // $order->calculate_totals(); $order->update_status("Completed", 'imported order', TRUE); }确保给定的产品ID在系统中。



