2015-12-10 11:55:03 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handles storage and retrieval of shipping zones
|
|
|
|
*
|
|
|
|
* @class WC_Shipping_Zones
|
|
|
|
* @version 2.5.0
|
|
|
|
* @package WooCommerce/Classes
|
|
|
|
* @category Class
|
|
|
|
* @author WooThemes
|
|
|
|
*/
|
|
|
|
class WC_Shipping_Zones {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get shipping zones from the database
|
2015-12-10 12:31:03 +00:00
|
|
|
* @return array of arrays
|
2015-12-10 11:55:03 +00:00
|
|
|
*/
|
|
|
|
public static function get_zones() {
|
|
|
|
global $wpdb;
|
|
|
|
|
2015-12-10 12:31:03 +00:00
|
|
|
$raw_zones = $wpdb->get_results( "SELECT zone_id, zone_name, zone_order FROM {$wpdb->prefix}woocommerce_shipping_zones order by zone_order ASC;" );
|
2015-12-10 11:55:03 +00:00
|
|
|
$zones = array();
|
|
|
|
|
|
|
|
foreach ( $raw_zones as $raw_zone ) {
|
2015-12-10 17:07:18 +00:00
|
|
|
$zone = new WC_Shipping_Zone( $raw_zone );
|
|
|
|
$zones[ $zone->get_zone_id() ] = $zone->get_data();
|
|
|
|
$zones[ $zone->get_zone_id() ]['formatted_zone_location'] = $zone->get_formatted_location();
|
2015-12-10 11:55:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $zones;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static function delete_zone( $zone_id ) {
|
|
|
|
global $wpdb;
|
|
|
|
$wpdb->delete( $wpdb->prefix . 'woocommerce_shipping_zone_locations', array( 'zone_id' => $zone_id ) );
|
|
|
|
$wpdb->delete( $wpdb->prefix . 'woocommerce_shipping_zones', array( 'zone_id' => $zone_id ) );
|
|
|
|
}
|
|
|
|
}
|