Abstract_WC_Order_Data_Store_CPT::update_order_from_object()
Given an initialized order object, update the post/postmeta records.
Method of the class: Abstract_WC_Order_Data_Store_CPT{}
No Hooks.
Return
true|false
. Whether the order was updated.
Usage
$Abstract_WC_Order_Data_Store_CPT = new Abstract_WC_Order_Data_Store_CPT(); $Abstract_WC_Order_Data_Store_CPT->update_order_from_object( $order );
- $order(WC_Abstract_Order) (required)
- Order object.
Abstract_WC_Order_Data_Store_CPT::update_order_from_object() Abstract WC Order Data Store CPT::update order from object code WC 9.4.2
public function update_order_from_object( $order ) { if ( ! $order->get_id() ) { return false; } $this->update_order_meta_from_object( $order ); // Add hook to update post_modified date so that it's the same as order. Without this hook, WP will set the modified date to current date, and we will think that posts and orders are out of sync again. add_filter( 'wp_insert_post_data', array( $this, 'update_post_modified_data' ), 10, 2 ); $post_data = array( 'ID' => $order->get_id(), '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_status' => $this->get_post_status( $order ), 'post_parent' => $order->get_parent_id(), 'edit_date' => true, 'post_excerpt' => method_exists( $order, 'get_customer_note' ) ? $order->get_customer_note() : '', 'post_type' => $order->get_type(), 'order_modified' => ! is_null( $order->get_date_modified() ) ? gmdate( 'Y-m-d H:i:s', $order->get_date_modified( 'edit' )->getOffsetTimestamp() ) : '', 'order_modified_gmt' => ! is_null( $order->get_date_modified() ) ? gmdate( 'Y-m-d H:i:s', $order->get_date_modified( 'edit' )->getTimestamp() ) : '', ); $updated = wp_update_post( $post_data ); remove_filter( 'wp_insert_post_data', array( $this, 'update_post_modified_data' ) ); return $updated; }