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. Ничего.


// 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 7.1.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 ) ) {

	// 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 posts and order data, although the sync is enabled.
	 * When order modified date is more recent than post modified date, it can only mean that COT definitely has more updated version of the order.
	 * In a case where post meta was updated (without updating post_modified date), post_modified would be equal to order_modified date.
	 * So we write back to the order table when order modified date is more recent than post modified date. Otherwise, we write to the post table.
	if ( $post_order_modified_date >= $order_modified_date ) {
		$this->migrate_post_record( $order, $post_order );