WC_REST_Taxes_Controller::add_tax_rate_locales()
Add tax rate locales to the response array.
Method of the class: WC_REST_Taxes_Controller{}
No Hooks.
Return
Array
.
Usage
// protected - for code of main (parent) or child class $result = $this->add_tax_rate_locales( $data, $tax );
- $data(array) (required)
- Response data.
- $tax(stdClass) (required)
- Tax object.
WC_REST_Taxes_Controller::add_tax_rate_locales() WC REST Taxes Controller::add tax rate locales code WC 9.5.1
protected function add_tax_rate_locales( $data, $tax ) { global $wpdb; $data = parent::add_tax_rate_locales( $data, $tax ); $data['postcodes'] = array(); $data['cities'] = array(); // Get locales from a tax rate. $locales = $wpdb->get_results( $wpdb->prepare( " SELECT location_code, location_type FROM {$wpdb->prefix}woocommerce_tax_rate_locations WHERE tax_rate_id = %d ", $tax->tax_rate_id ) ); if ( ! is_wp_error( $tax ) && ! is_null( $tax ) ) { foreach ( $locales as $locale ) { if ( 'postcode' === $locale->location_type ) { $data['postcodes'][] = $locale->location_code; } elseif ( 'city' === $locale->location_type ) { $data['cities'][] = $locale->location_code; } } } return $data; }