Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableDataStore::create()publicWC 1.0

Method to create an order in the database.

Method of the class: OrdersTableDataStore{}

Hooks from the method

Return

null. Nothing (null).

Usage

$OrdersTableDataStore = new OrdersTableDataStore();
$OrdersTableDataStore->create( $order );
$order(\WC_Order) (required) (passed by reference — &)
Order object.

OrdersTableDataStore::create() code WC 9.3.3

public function create( &$order ) {
	if ( '' === $order->get_order_key() ) {
		$order->set_order_key( wc_generate_order_key() );
	}

	$this->persist_save( $order );

	// Do not fire 'woocommerce_new_order' for draft statuses for backwards compatibility.
	if ( in_array( $order->get_status( 'edit' ), array( 'auto-draft', 'draft', 'checkout-draft' ), true ) ) {
		return;
	}

	/**
	 * Fires when a new order is created.
	 *
	 * @since 2.7.0
	 *
	 * @param int       Order ID.
	 * @param \WC_Order Order object.
	 */
	do_action( 'woocommerce_new_order', $order->get_id(), $order );
}