WC_Shipping_Zone::get_formatted_location()publicWC 1.0

Return a text string representing what this zone is for.

Method of the class: WC_Shipping_Zone{}

No Hooks.

Return

String.

Usage

$WC_Shipping_Zone = new WC_Shipping_Zone();
$WC_Shipping_Zone->get_formatted_location( $max, $context );
$max(int)
Max locations to return.
Default: 10
$context(string)
View or edit context.
Default: 'view'

WC_Shipping_Zone::get_formatted_location() code WC 8.6.1

public function get_formatted_location( $max = 10, $context = 'view' ) {
	$location_parts = array();
	$all_continents = WC()->countries->get_continents();
	$all_countries  = WC()->countries->get_countries();
	$all_states     = WC()->countries->get_states();
	$locations      = $this->get_zone_locations( $context );
	$continents     = array_filter( $locations, array( $this, 'location_is_continent' ) );
	$countries      = array_filter( $locations, array( $this, 'location_is_country' ) );
	$states         = array_filter( $locations, array( $this, 'location_is_state' ) );
	$postcodes      = array_filter( $locations, array( $this, 'location_is_postcode' ) );

	foreach ( $continents as $location ) {
		$location_parts[] = $all_continents[ $location->code ]['name'];
	}

	foreach ( $countries as $location ) {
		$location_parts[] = $all_countries[ $location->code ];
	}

	foreach ( $states as $location ) {
		$location_codes   = explode( ':', $location->code );
		$location_parts[] = $all_states[ $location_codes[0] ][ $location_codes[1] ];
	}

	foreach ( $postcodes as $location ) {
		$location_parts[] = $location->code;
	}

	// Fix display of encoded characters.
	$location_parts = array_map( 'html_entity_decode', $location_parts );

	if ( count( $location_parts ) > $max ) {
		$remaining = count( $location_parts ) - $max;
		// @codingStandardsIgnoreStart
		return sprintf( _n( '%s and %d other region', '%s and %d other regions', $remaining, 'woocommerce' ), implode( ', ', array_splice( $location_parts, 0, $max ) ), $remaining );
		// @codingStandardsIgnoreEnd
	} elseif ( ! empty( $location_parts ) ) {
		return implode( ', ', $location_parts );
	} else {
		return __( 'Everywhere', 'woocommerce' );
	}
}