Automattic\WooCommerce\Internal

OrderCouponDataMigrator::handle_woocommerce_debug_tools()privateWC 1.0

Add the tool to start or stop the background process that converts order coupon metadata entries.

Method of the class: OrderCouponDataMigrator{}

No Hooks.

Return

Array. Updated tools array.

Usage

// private - for code of main (parent) class only
$result = $this->handle_woocommerce_debug_tools( $tools ): array;
$tools(array) (required)
Old tools array.

OrderCouponDataMigrator::handle_woocommerce_debug_tools() code WC 9.3.3

private function handle_woocommerce_debug_tools( array $tools ): array {
	$batch_processor = wc_get_container()->get( BatchProcessingController::class );
	$pending_count   = $this->get_total_pending_count();

	if ( 0 === $pending_count ) {
		$tools['start_convert_order_coupon_data'] = array(
			'name'     => __( 'Start converting order coupon data to the simplified format', 'woocommerce' ),
			'button'   => __( 'Start converting', 'woocommerce' ),
			'disabled' => true,
			'desc'     => __( 'This will convert <code>coupon_data</code> order item meta entries to simplified <code>coupon_info</code> entries. The conversion will happen overtime in the background (via Action Scheduler). There are currently no entries to convert.', 'woocommerce' ),
		);
	} elseif ( $batch_processor->is_enqueued( self::class ) ) {
		$tools['stop_convert_order_coupon_data'] = array(
			'name'     => __( 'Stop converting order coupon data to the simplified format', 'woocommerce' ),
			'button'   => __( 'Stop converting', 'woocommerce' ),
			'desc'     =>
				/* translators: %d=count of entries pending conversion */
				sprintf( __( 'This will stop the background process that converts <code>coupon_data</code> order item meta entries to simplified <code>coupon_info</code> entries. There are currently %d entries that can be converted.', 'woocommerce' ), $pending_count ),
			'callback' => array( $this, 'dequeue' ),
		);
	} else {
		$tools['start_converting_order_coupon_data'] = array(
			'name'     => __( 'Convert order coupon data to the simplified format', 'woocommerce' ),
			'button'   => __( 'Start converting', 'woocommerce' ),
			'desc'     =>
				/* translators: %d=count of entries pending conversion */
				sprintf( __( 'This will convert <code>coupon_data</code> order item meta entries to simplified <code>coupon_info</code> entries. The conversion will happen overtime in the background (via Action Scheduler). There are currently %d entries that can be converted.', 'woocommerce' ), $pending_count ),
			'callback' => array( $this, 'enqueue' ),
		);
	}

	return $tools;
}