Abstract_WC_Order_Data_Store_CPT::create()publicWC 1.0

Method to create a new order in the database.

Method of the class: Abstract_WC_Order_Data_Store_CPT{}

Hooks from the method

Return

null. Nothing (null).

Usage

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

Abstract_WC_Order_Data_Store_CPT::create() code WC 9.4.2

public function create( &$order ) {
	$order->set_version( Constants::get_constant( 'WC_VERSION' ) );
	$order->set_currency( $order->get_currency() ? $order->get_currency() : get_woocommerce_currency() );
	if ( ! $order->get_date_created( 'edit' ) ) {
		$order->set_date_created( time() );
	}

	$id = wp_insert_post(
		/**
		 * Filters the data for a new order before it is inserted into the database.
		 *
		 * @param array $data Array of data for the new order.
		 *
		 * @since 3.3.0
		 */
		apply_filters(
			'woocommerce_new_order_data',
			array(
				'post_date'     => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getOffsetTimestamp() ),
				'post_date_gmt' => gmdate( 'Y-m-d H:i:s', $order->get_date_created( 'edit' )->getTimestamp() ),
				'post_type'     => $order->get_type( 'edit' ),
				'post_status'   => $this->get_post_status( $order ),
				'ping_status'   => 'closed',
				'post_author'   => 1,
				'post_title'    => $this->get_post_title(),
				'post_password' => $this->get_order_key( $order ),
				'post_parent'   => $order->get_parent_id( 'edit' ),
				'post_excerpt'  => $this->get_post_excerpt( $order ),
			)
		),
		true
	);

	if ( $id && ! is_wp_error( $id ) ) {
		$order->set_id( $id );
		$this->update_post_meta( $order );
		$order->save_meta_data();
		$order->apply_changes();
		$this->clear_caches( $order );
	}
}