WC_Shipping_Zone_Data_Store::read( WC_Shipping_Zone $zone )

Method to read a shipping zone from the database.


Description Description


Parameters Parameters

$zone

(Required) Shipping zone object.


Top ↑

Source Source

File: includes/data-stores/class-wc-shipping-zone-data-store.php

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

		$zone_data = false;

		if ( 0 !== $zone->get_id() || '0' !== $zone->get_id() ) {
			$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 ( 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 );
			do_action( 'woocommerce_shipping_zone_loaded', $zone );
		} elseif ( $zone_data ) {
			$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 );
			do_action( 'woocommerce_shipping_zone_loaded', $zone );
		} else {
			throw new Exception( __( 'Invalid data store.', 'woocommerce' ) );
		}
	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.