Automattic\WooCommerce\Admin\Features\Fulfillments

FulfillmentUtils::get_shipping_providerspublic staticWC 1.0

Get the shipping providers.

This method retrieves the shipping providers registered in the WooCommerce Fulfillments system. It can be filtered using the woocommerce_fulfillment_shipping_providers

Any class name strings in the filter result are resolved into AbstractShippingProvider instances via the DI container. Invalid entries are silently skipped.

Method of the class: FulfillmentUtils{}

Returns

AbstractShippingProvider[]. An associative array of shipping provider instances keyed by provider key.

Usage

$result = FulfillmentUtils::get_shipping_providers(): array;

FulfillmentUtils::get_shipping_providers() code WC 10.7.0

public static function get_shipping_providers(): array {
	/**
	 * This filter allows plugins to modify the list of shipping providers.
	 * It can be used to add, remove, or change the shipping providers available in the
	 * WooCommerce Fulfillments system.
	 *
	 * @since 10.1.0
	 *
	 * @param array $shipping_providers The default list of shipping providers.
	 */
	$raw_providers = apply_filters(
		'woocommerce_fulfillment_shipping_providers',
		array()
	);

	if ( ! is_array( $raw_providers ) ) {
		return array();
	}

	$resolved = array();
	foreach ( $raw_providers as $provider ) {
		if ( $provider instanceof AbstractShippingProvider ) {
			$resolved[ $provider->get_key() ] = $provider;
		} elseif ( is_string( $provider )
			&& class_exists( $provider )
			&& is_subclass_of( $provider, AbstractShippingProvider::class )
		) {
			try {
				$instance = wc_get_container()->get( $provider );
			} catch ( \Throwable $e ) {
				continue;
			}
			$resolved[ $instance->get_key() ] = $instance;
		}
	}

	return $resolved;
}