Automattic\WooCommerce\Internal\RestApi\Routes\V4\Fulfillments

Controller::get_providerspublicWC 10.5.0

Get all shipping providers.

Method of the class: Controller{}

Returns

WP_REST_Response.

Usage

$Controller = new Controller();
$Controller->get_providers( $request ): WP_REST_Response;
$request(WP_REST_Request) (required)
Full details about the request.

Changelog

Since 10.5.0 Introduced.

Controller::get_providers() code WC 10.7.0

public function get_providers( WP_REST_Request $request ): WP_REST_Response {
	$providers = array();
	foreach ( \Automattic\WooCommerce\Admin\Features\Fulfillments\FulfillmentUtils::get_shipping_providers() as $provider ) {
		$providers[ $provider->get_key() ] = array(
			'label' => $provider->get_name(),
			'icon'  => $provider->get_icon(),
			'value' => $provider->get_key(),
			'url'   => $provider->get_tracking_url( '__PLACEHOLDER__' ) ?? '',
		);
	}

	/**
	 * Filters the shipping providers response before it is returned.
	 *
	 * Each provider in the array must have the following structure:
	 * - 'label' (string): The display name of the provider.
	 * - 'icon' (string): URL to the provider's icon.
	 * - 'value' (string): The provider's unique identifier.
	 * - 'url' (string): The tracking URL template.
	 *
	 * @param array           $providers The shipping providers data.
	 * @param WP_REST_Request $request   The request object.
	 *
	 * @since 10.5.0
	 */
	$providers = apply_filters( 'woocommerce_rest_prepare_fulfillments_providers', $providers, $request );

	// Validate filtered result to prevent extensions from returning invalid structures.
	if ( ! is_array( $providers ) ) {
		_doing_it_wrong(
			'woocommerce_rest_prepare_fulfillments_providers',
			esc_html__( 'The filter must return an array of providers.', 'woocommerce' ),
			'10.5.0'
		);
		$providers = array();
	} else {
		$providers = $this->validate_providers_structure( $providers );
	}

	return new WP_REST_Response( $providers, WP_Http::OK );
}