Automattic\WooCommerce\Internal\DataStores\Orders
LegacyDataHandler::is_order_newer_than_post
Checks whether an HPOS-backed order is newer than the corresponding post.
Method of the class: LegacyDataHandler{}
No Hooks.
Returns
true|false. TRUE if the order is up to date with the corresponding post.
Usage
// private - for code of main (parent) class only $result = $this->is_order_newer_than_post( $order ): bool;
- $order(WC_Abstract_Order) (required)
- An HPOS order.
LegacyDataHandler::is_order_newer_than_post() LegacyDataHandler::is order newer than post code WC 10.3.5
private function is_order_newer_than_post( \WC_Abstract_Order $order ): bool {
if ( ! is_a( $order->get_data_store()->get_current_class_name(), OrdersTableDataStore::class, true ) ) {
throw new \Exception( esc_html__( 'Order is not an HPOS order.', 'woocommerce' ) );
}
$post = get_post( $order->get_id() );
if ( ! $post || $this->data_synchronizer::PLACEHOLDER_ORDER_POST_TYPE === $post->post_type ) {
return true;
}
$order_modified_gmt = $order->get_date_modified() ?? $order->get_date_created();
$order_modified_gmt = $order_modified_gmt ? $order_modified_gmt->getTimestamp() : 0;
$post_modified_gmt = $post->post_modified_gmt ?? $post->post_date_gmt;
$post_modified_gmt = ( $post_modified_gmt && '0000-00-00 00:00:00' !== $post_modified_gmt ) ? wc_string_to_timestamp( $post_modified_gmt ) : 0;
return $order_modified_gmt >= $post_modified_gmt;
}