Wordpress (Woocommerce extension) - Create new order programmatically

后端 未结 8 1624
小蘑菇
小蘑菇 2021-01-31 11:29

I want to create a new order programmatically.

Workflow is simple: After submitting simple form, user will be created and along with that, a new order.

I managed

8条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-31 11:45

    As of WooCommerce 2.2 (or maybe 2.1 I'm not 100% sure) there is now a function specifically designed for this.

    wc_create_order( $args = array() )
    

    with the following default arguments.

    $default_args = array(
        'status'        => '',
        'customer_id'   => null,
        'customer_note' => null,
        'order_id'      => 0
    );
    

    You can see the whole function in the includes/wc-core-functions.php file.

提交回复
热议问题