Automattic\WooCommerce\Internal\DataStores\Orders

LegacyDataHandler::is_order_newer_than_post()privateWC 1.0

Checks whether an HPOS-backed order is newer than the corresponding post.

Метод класса: LegacyDataHandler{}

Хуков нет.

Возвращает

true|false. TRUE if the order is up to date with the corresponding post.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->is_order_newer_than_post( $order ): bool;
$order(\WC_Abstract_Order) (обязательный)
An HPOS order.

Код LegacyDataHandler::is_order_newer_than_post() WC 9.7.1

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;
}