Automattic\WooCommerce\Internal\DataStores\Orders

OrdersTableDataStore::maybe_sync_order()privateWC 1.0

Sync order to/from posts tables if we are able to detect difference between order and posts but the sync is enabled.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

// private - только в коде основоного (родительского) класса
$result = $this->maybe_sync_order( $order, $post_order );
$order(\WC_Abstract_Order) (обязательный)
Order object.
$post_order(\WC_Abstract_Order) (обязательный)
Order object initialized from post.

Код OrdersTableDataStore::maybe_sync_order() WC 8.7.0

private function maybe_sync_order( \WC_Abstract_Order &$order, \WC_Abstract_Order $post_order ) {
	if ( ! $this->is_post_different_from_order( $order, $post_order ) ) {
		return;
	}

	// Modified dates can be empty when the order is created but never updated again. Fallback to created date in those cases.
	$order_modified_date      = $order->get_date_modified() ?? $order->get_date_created();
	$order_modified_date      = is_null( $order_modified_date ) ? 0 : $order_modified_date->getTimestamp();
	$post_order_modified_date = $post_order->get_date_modified() ?? $post_order->get_date_created();
	$post_order_modified_date = is_null( $post_order_modified_date ) ? 0 : $post_order_modified_date->getTimestamp();

	/**
	 * We are here because there was difference in the post and order data even though sync is enabled. If the modified date in
	 * the post is the same or more recent than the modified date in the order object, we update the order object with the data
	 * from the post. The opposite case is handled in 'backfill_post_record'. This mitigates the case where other plugins write
	 * to the post or postmeta directly.
	 */
	if ( $post_order_modified_date >= $order_modified_date ) {
		$this->migrate_post_record( $order, $post_order );
	}
}