Automattic\WooCommerce\Internal\Admin\Schedulers

OrdersScheduler::importpublic staticWC 1.0

Imports a single order or refund to update lookup tables for. If an error is encountered in one of the updates, a retry action is scheduled.

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

Возвращает

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

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

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

Код OrdersScheduler::import() WC 10.3.4

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

	$results = array(
		OrdersStatsDataStore::sync_order( $order_id ),
		ProductsDataStore::sync_order_products( $order_id ),
		CouponsDataStore::sync_order_coupons( $order_id ),
		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();

	/**
	 * 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 );
}