Automattic\WooCommerce\Internal\RestApi\Routes\V4\Settings\OfflinePaymentMethods

Controller::get_offline_payment_methods_dataprivateWC 1.0

Get offline payment methods data.

Method of the class: Controller{}

No Hooks.

Returns

Array|WP_Error. The offline payment methods data or error.

Usage

// private - for code of main (parent) class only
$result = $this->get_offline_payment_methods_data( $request );
$request(WP_REST_Request) (required)
Full details about the request.

Controller::get_offline_payment_methods_data() code WC 10.4.3

private function get_offline_payment_methods_data( $request ) {
	$location = sanitize_text_field( $request->get_param( 'location' ) );

	if ( empty( $location ) ) {
		// Fall back to the payments country if no location is provided.
		$location = $this->payments->get_country();
	}

	try {
		$providers = $this->payments->get_payment_providers( $location );
	} catch ( \Exception $e ) {
		return new \WP_Error( 'woocommerce_rest_payment_providers_error', $e->getMessage(), array( 'status' => 500 ) );
	}

	if ( is_wp_error( $providers ) ) {
		return $providers;
	}

	// Retrieve the offline PMs from the main providers list.
	$offline_payment_providers = array_values(
		array_filter(
			$providers,
			fn( $provider ) => isset( $provider['_type'] ) && PaymentsProviders::TYPE_OFFLINE_PM === $provider['_type']
		)
	);

	return $offline_payment_providers;
}