WordPress at Your Fingertips
function is not described

WC_Shipping_Zone_Data_Store::save_locations() private WC 3.0.0

Save locations to the DB. This function clears old locations, then re-inserts new if any changes are found.

{} It's a method of the class: WC_Shipping_Zone_Data_Store{}

No Hooks.

Return

true|false|null.

Usage

// private - for code of main (parent) class only
$result = $this->save_locations( $zone );
$zone(WC_Shipping_Zone) (required) (passed by reference — &)
Shipping zone object.

Changelog

Since 3.0.0 Introduced.

Code of WC_Shipping_Zone_Data_Store::save_locations() WC 5.7.0

private function save_locations( &$zone ) {
	$changed_props = array_keys( $zone->get_changes() );
	if ( ! in_array( 'zone_locations', $changed_props, true ) ) {
		return false;
	}

	global $wpdb;
	$wpdb->delete( $wpdb->prefix . 'woocommerce_shipping_zone_locations', array( 'zone_id' => $zone->get_id() ) );

	foreach ( $zone->get_zone_locations( 'edit' ) as $location ) {
		$wpdb->insert(
			$wpdb->prefix . 'woocommerce_shipping_zone_locations',
			array(
				'zone_id'       => $zone->get_id(),
				'location_code' => $location->code,
				'location_type' => $location->type,
			)
		);
	}
}