WC_Shipping_Zone_Data_Store::save_locations
Save locations to the DB. This function clears old locations, then re-inserts new if any changes are found.
Method of the class: WC_Shipping_Zone_Data_Store{}
No Hooks.
Returns
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. |
WC_Shipping_Zone_Data_Store::save_locations() WC Shipping Zone Data Store::save locations code WC 10.3.6
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,
)
);
}
}