WC_REST_Taxes_V1_Controller::add_tax_rate_locales
Add tax rate locales to the response array.
Method of the class: WC_REST_Taxes_V1_Controller{}
No Hooks.
Returns
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_V1_Controller::add_tax_rate_locales() WC REST Taxes V1 Controller::add tax rate locales code WC 10.5.0
protected function add_tax_rate_locales( $data, $tax ) {
global $wpdb;
// 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 ) {
$data[ $locale->location_type ] = $locale->location_code;
}
}
return $data;
}