Automattic\WooCommerce\Admin\Features\Blueprint\Importers

ImportSetWCPaymentGateways::process()publicWC 1.0

Process the import of WooCommerce payment gateways settings.

Method of the class: ImportSetWCPaymentGateways{}

Hooks from the method

Return

StepProcessorResult.

Usage

$ImportSetWCPaymentGateways = new ImportSetWCPaymentGateways();
$ImportSetWCPaymentGateways->process( $schema ): StepProcessorResult;
$schema(object) (required)
The schema object containing import details.

ImportSetWCPaymentGateways::process() code WC 9.7.1

public function process( $schema ): StepProcessorResult {
	$result           = StepProcessorResult::success( SetWCPaymentGateways::get_step_name() );
	$payment_gateways = $this->get_wc_payment_gateways();
	$fields           = array( 'title', 'description', 'enabled' );

	foreach ( $schema->payment_gateways as $id => $payment_gateway_data ) {
		if ( ! isset( $payment_gateways[ $id ] ) ) {
			$result->add_info( "Skipping {$id}. The payment gateway is not available" );
			continue;
		}

		$payment_gateway = $payment_gateways[ $id ];

		// Refer to https://github.com/woocommerce/woocommerce/blob/trunk/plugins/woocommerce/includes/class-wc-ajax.php#L3564.
		foreach ( $fields as $field ) {
			if ( isset( $payment_gateway_data->{$field} ) ) {
				$payment_gateway->update_option( $field, $payment_gateway_data->{$field} );
			}
		}
		$result->add_info( "{$id} has been updated." );
		$this->wp_do_action( 'woocommerce_update_options' );
	}

	return $result;
}