Automattic\WooCommerce\Admin\Features\Fulfillments

FulfillmentUtils::get_provider_display_name │ public static │ WC 11.3.0

Resolve the human-readable provider label for display.

Unlike {@see self::resolve_provider_name()}, which returns the stable slug for known providers, this returns the provider's display name (e.g. "DHL" for "dhl") so it can be shown to customers. Custom providers use the merchant-entered name, and an unknown slug falls back to that name or the slug itself.

Method of the class: FulfillmentUtils{}

Returns

string. The provider label to display.

Usage

$result = FulfillmentUtils::get_provider_display_name( $fulfillment ): string;
$fulfillment(Fulfillment) (required)
The fulfillment object.

Changelog

Since 11.3.0 Introduced.

FulfillmentUtils::get_provider_display_name() code WC 11.3.0

public static function get_provider_display_name( Fulfillment $fulfillment ): string {
	$provider_slug     = $fulfillment->get_shipment_provider() ?? '';
	$provider_name_raw = $fulfillment->get_meta( '_provider_name', true );
	$provider_name     = is_scalar( $provider_name_raw ) ? (string) $provider_name_raw : '';

	// 'other' is the reserved sentinel for a merchant-entered custom provider, so its
	// name always comes from meta, never from a provider that happens to share the key.
	if ( 'other' === $provider_slug ) {
		$label = '' !== $provider_name ? $provider_name : $provider_slug;
	} else {
		$known_providers = self::get_shipping_providers();
		if ( isset( $known_providers[ $provider_slug ] ) ) {
			$label = $known_providers[ $provider_slug ]->get_name();
		} else {
			$label = '' !== $provider_name ? $provider_name : $provider_slug;
		}
	}

	/**
	 * Filters the shipment provider label shown to customers.
	 *
	 * @since 11.3.0
	 *
	 * @param string      $label       The resolved provider label.
	 * @param Fulfillment $fulfillment The fulfillment object.
	 */
	$filtered_label = apply_filters( 'woocommerce_fulfillment_shipment_provider_label', $label, $fulfillment );

	// Keep the resolved label if a callback returns something that can't be rendered as text.
	return is_scalar( $filtered_label ) ? (string) $filtered_label : $label;
}