Automattic\WooCommerce\Internal\Admin

Analytics::run_full_refund_fix_data_toolpublicWC 10.8.0

Handles the Fix button submission for the full refund fix tool.

When the "Disable tool" action is requested (i.e. the Check confirmed no affected orders), deletes the old-data flag so the tool no longer appears. Otherwise schedules the first batch job to re-import all affected refund orders.

Method of the class: Analytics{}

No Hooks.

Returns

String. Success message.

Usage

$Analytics = new Analytics();
$Analytics->run_full_refund_fix_data_tool();

Changelog

Since 10.8.0 Introduced.

Analytics::run_full_refund_fix_data_tool() code WC 10.9.3

public function run_full_refund_fix_data_tool() {
	// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verified by WooCommerce tools framework.
	if ( isset( $_GET['wc_refund_fix_action'] ) && 'disable' === sanitize_key( $_GET['wc_refund_fix_action'] ) ) {
		delete_option( 'woocommerce_analytics_uses_old_full_refund_data' );
		delete_option( 'woocommerce_analytics_show_old_refund_data_tool' );
		return __( 'Tool dismissed.', 'woocommerce' );
	}

	$already_running = ! empty(
		as_get_scheduled_actions(
			array(
				'hook'     => 'woocommerce_analytics_refund_fix_batch',
				'status'   => array( \ActionScheduler_Store::STATUS_PENDING, \ActionScheduler_Store::STATUS_RUNNING ),
				'per_page' => 1,
				'orderby'  => 'none',
			),
			'ids'
		)
	);

	if ( $already_running ) {
		return __( 'A fix is already in progress, please check back later.', 'woocommerce' );
	}

	// Clear the legacy flag before queuing so that every batch job runs with
	// the corrected full-refund import logic (uses_new_full_refund_data() → true).
	// Set the show-tool option so the tool stays visible until the merchant dismisses it.
	delete_option( 'woocommerce_analytics_uses_old_full_refund_data' );
	update_option( 'woocommerce_analytics_show_old_refund_data_tool', 'yes' );

	WC()->queue()->schedule_single(
		time(),
		'woocommerce_analytics_refund_fix_batch',
		array( 0 ),
		'wc-admin-data'
	);

	return __( 'Re-importing refunded orders in batches. Full refund data will be updated shortly.', 'woocommerce' );
}