WC_REST_Taxes_V1_Controller::add_tax_rate_locales()protectedWC 1.0

Add tax rate locales to the response array.

Method of the class: WC_REST_Taxes_V1_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_V1_Controller::add_tax_rate_locales() code WC 8.7.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;
}