WC_Countries::get_shipping_countries │ public │ WC 1.0

Get countries that the store ships to.

Method of the class: WC_Countries{}

Returns

array.

Usage

$WC_Countries = new WC_Countries();
$WC_Countries->get_shipping_countries();

WC_Countries::get_shipping_countries() code WC 11.2.1

public function get_shipping_countries() {
	// If shipping is disabled, return an empty array.
	if ( 'disabled' === get_option( 'woocommerce_ship_to_countries' ) ) {
		return array();
	}

	// Default to selling countries.
	$countries = $this->get_allowed_countries();

	// All indicates that all countries are allowed, regardless of where you sell to.
	if ( 'all' === get_option( 'woocommerce_ship_to_countries' ) ) {
		$countries = $this->read_geo_property( 'countries' );
	} elseif ( 'specific' === get_option( 'woocommerce_ship_to_countries' ) ) {
		$all_countries = $this->read_geo_property( 'countries' );
		$countries     = array();
		$raw_countries = get_option( 'woocommerce_specific_ship_to_countries', array() );

		if ( $raw_countries ) {
			foreach ( $raw_countries as $country ) {
				// The list is empty while it is being built, so a lookup made from a country filter gets no entries.
				if ( isset( $all_countries[ $country ] ) ) {
					$countries[ $country ] = $all_countries[ $country ];
				}
			}
		}
	}

	/**
	 * Filter the list of allowed selling countries.
	 *
	 * @since 3.3.0
	 * @param array $countries
	 */
	return apply_filters( 'woocommerce_countries_shipping_countries', $countries );
}