Automattic\WooCommerce\Internal\Admin\Schedulers

OrdersScheduler::import │ public static │ WC 1.0

Imports a single order or refund to update lookup tables for. An order whose tax lookup rows could not be written stays on the failed imports list.

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

Возвращает

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

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

$result = OrdersScheduler::import( $order_id );
$order_id(int) (обязательный)
Order or refund ID.

Код OrdersScheduler::import() WC 11.3.0

public static function import( $order_id ) {
	$order = wc_get_order( $order_id );

	// If the order isn't found for some reason, skip the sync.
	if ( ! $order ) {
		return;
	}

	$type = $order->get_type();

	// If the order isn't the right type, skip sync.
	if ( 'shop_order' !== $type && 'shop_order_refund' !== $type ) {
		return;
	}

	// If the order has no id or date created, skip sync.
	if ( ! $order->get_id() || ! $order->get_date_created() ) {
		return;
	}

	// Skip test orders (e.g., WCPay test mode) from analytics.
	if ( self::is_test_order( $order ) ) {
		wc_get_logger()->debug(
			sprintf( 'Skipping test order #%d from analytics import.', $order_id ),
			array( 'source' => 'wc-analytics-order-import' )
		);
		return;
	}

	// Skip trashed records Analytics does not already hold: importing one creates a
	// wc_customer_lookup row via Order::get_report_customer_id() that nothing removes
	// while the order stays trashed. Records trashed after being imported keep their
	// stats row, so their status still syncs.
	if ( OrderStatus::TRASH === $order->get_status() && ! self::has_order_stats_row( $order_id ) ) {
		return;
	}

	OrdersStatsDataStore::sync_order( $order_id );
	ProductsDataStore::sync_order_products( $order_id );
	CouponsDataStore::sync_order_coupons( $order_id );
	$taxes_synced = TaxesDataStore::sync_order_taxes( $order_id );
	CustomersDataStore::sync_order_customer( $order_id );

	if ( 'shop_order' === $type ) {
		$order_refunds = $order->get_refunds();

		foreach ( $order_refunds as $refund ) {
			OrdersStatsDataStore::sync_order( $refund->get_id() );
		}
	}

	ReportsCache::invalidate();

	// A tax sync that did not land leaves the order holding the lookup rows it came in with,
	// so the import did not finish and the order stays on the list Analytics settings retries
	// over. Only this sync is read: the other stores return false for writes that changed no
	// rows as well, so their return value does not tell a failure from an order that was
	// already up to date.
	if ( false === $taxes_synced ) {
		self::record_failed_order_import( $order_id );
	} else {
		self::clear_failed_order_import( $order_id );
	}

	/**
	 * Fires after an order or refund has been imported into Analytics lookup tables
	 * and the reports cache has been invalidated.
	 *
	 * @since 10.3.0
	 * @param int $order_id Order or refund ID.
	 */
	do_action( 'woocommerce_order_scheduler_after_import_order', $order_id );
}