* @param string $tax_class * * @return array|null|object */ public static function get_rates_for_tax_class($tax_class) { global $wpdb; // Get all the rates and locations. Snagging all at once should significantly cut down on the number of queries. $rates = self::sort_rates($wpdb->get_results($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}woocommerce_tax_rates` WHERE `tax_rate_class` = %s;", sanitize_title($tax_class)))); $locations = $wpdb->get_results("SELECT * FROM `{$wpdb->prefix}woocommerce_tax_rate_locations`"); if (!empty($rates)) { // Set the rates keys equal to their ids. $rates = array_combine(wp_list_pluck($rates, 'tax_rate_id'), $rates); } // Drop the locations into the rates array. foreach ($locations as $location) { // Don't set them for unexistent rates. if (!isset($rates[$location->tax_rate_id])) { continue; } // If the rate exists, initialize the array before appending to it. if (!isset($rates[$location->tax_rate_id]->{$location->location_type})) { $rates[$location->tax_rate_id]->{$location->location_type} = array(); } $rates[$location->tax_rate_id]->{$location->location_type}[] = $location->location_code; } return $rates; } } WC_Tax::init();