WC_Shipping_Zone_Data_Store::read_multiple
Reads multiple WC_Shipping_Zone objects from the data store.
Method of the class: WC_Shipping_Zone_Data_Store{}
Hooks from the method
Returns
null. Nothing (null).
Usage
$WC_Shipping_Zone_Data_Store = new WC_Shipping_Zone_Data_Store(); $WC_Shipping_Zone_Data_Store->read_multiple( $zones );
- $zones(WC_Shipping_Zone[]) (required)
- Array of zones to read keyed by the zone_id.
WC_Shipping_Zone_Data_Store::read_multiple() WC Shipping Zone Data Store::read multiple code WC 10.3.3
public function read_multiple( array &$zones ) {
$zone_ids = array_keys( $zones );
$zone_data = $this->get_zone_data_for_ids( $zone_ids );
foreach ( $zones as $zone_id => $zone ) {
if ( 0 === $zone_id || '0' === $zone_id ) {
$zone->set_zone_name( __( 'Locations not covered by your other zones', 'woocommerce' ) );
} else {
if ( ! isset( $zone_data[ $zone_id ] ) ) {
throw new Exception( __( 'Invalid data store.', 'woocommerce' ) ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
}
$zone->set_zone_name( $zone_data[ $zone_id ]->zone_name );
$zone->set_zone_order( $zone_data[ $zone_id ]->zone_order );
}
}
$zone_locations = $this->get_zone_locations_for_ids( $zone_ids );
foreach ( $zone_locations as $zone_location ) {
if ( isset( $zones[ $zone_location->zone_id ] ) ) {
$zones[ $zone_location->zone_id ]->add_location( $zone_location->location_code, $zone_location->location_type );
}
}
foreach ( $zones as $zone_id => $zone ) {
$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 );
}
}