Abstract_WC_Order_Data_Store_CPT::create( WC_Order $order )
Method to create a new order in the database.
Description Description
Parameters Parameters
- $order
-
(Required) Order object.
Source Source
File: includes/data-stores/abstract-wc-order-data-store-cpt.php
public function create( &$order ) { $order->set_version( Constants::get_constant( 'WC_VERSION' ) ); $order->set_date_created( time() ); $order->set_currency( $order->get_currency() ? $order->get_currency() : get_woocommerce_currency() ); $id = wp_insert_post( 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' => wc_generate_order_key(), '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 ); } }