WC_Shipping_Zone_Data_Store::read()publicWC 3.0.0

Method to read a shipping zone from the database.

Method of the class: WC_Shipping_Zone_Data_Store{}

Hooks from the method

Return

null. Nothing (null).

Usage

$WC_Shipping_Zone_Data_Store = new WC_Shipping_Zone_Data_Store();
$WC_Shipping_Zone_Data_Store->read( $zone );
$zone(WC_Shipping_Zone) (required) (passed by reference — &)
Shipping zone object.

Changelog

Since 3.0.0 Introduced.

WC_Shipping_Zone_Data_Store::read() code WC 9.4.2

public function read( &$zone ) {
	global $wpdb;

	// Zone 0 is used as a default if no other zones fit.
	if ( 0 === $zone->get_id() || '0' === $zone->get_id() ) {
		$this->read_zone_locations( $zone );
		$zone->set_zone_name( __( 'Locations not covered by your other zones', 'woocommerce' ) );
		$zone->read_meta_data();
		$zone->set_object_read( true );

		/**
		 * Indicate that the WooCommerce shipping zone has been loaded.
		 *
		 * @param WC_Shipping_Zone $zone The shipping zone that has been loaded.
		 */
		do_action( 'woocommerce_shipping_zone_loaded', $zone );
		return;
	}

	$zone_data = $wpdb->get_row(
		$wpdb->prepare(
			"SELECT zone_name, zone_order FROM {$wpdb->prefix}woocommerce_shipping_zones WHERE zone_id = %d LIMIT 1",
			$zone->get_id()
		)
	);

	if ( ! $zone_data ) {
		throw new Exception( __( 'Invalid data store.', 'woocommerce' ) );
	}

	$zone->set_zone_name( $zone_data->zone_name );
	$zone->set_zone_order( $zone_data->zone_order );
	$this->read_zone_locations( $zone );
	$zone->read_meta_data();
	$zone->set_object_read( true );

	/** This action is documented in includes/datastores/class-wc-shipping-zone-data-store.php. */
	do_action( 'woocommerce_shipping_zone_loaded', $zone );
}