WC_Tax::update_tax_rate_locations()private staticWC 2.3.0

Updates locations (postcode and city).

Internal use only.

Method of the class: WC_Tax{}

No Hooks.

Return

null. Nothing (null).

Usage

$result = WC_Tax::update_tax_rate_locations( $tax_rate_id, $values, $type );
$tax_rate_id(int) (required)
Tax rate ID to update.
$values(array) (required)
Values to set.
$type(string) (required)
Location type.

Changelog

Since 2.3.0 Introduced.

WC_Tax::update_tax_rate_locations() code WC 8.6.1

private static function update_tax_rate_locations( $tax_rate_id, $values, $type ) {
	global $wpdb;

	$tax_rate_id = absint( $tax_rate_id );

	$wpdb->query(
		$wpdb->prepare(
			"DELETE FROM {$wpdb->prefix}woocommerce_tax_rate_locations WHERE tax_rate_id = %d AND location_type = %s;",
			$tax_rate_id,
			$type
		)
	);

	if ( count( $values ) > 0 ) {
		$sql = "( '" . implode( "', $tax_rate_id, '" . esc_sql( $type ) . "' ),( '", array_map( 'esc_sql', $values ) ) . "', $tax_rate_id, '" . esc_sql( $type ) . "' )";

		$wpdb->query( "INSERT INTO {$wpdb->prefix}woocommerce_tax_rate_locations ( location_code, tax_rate_id, location_type ) VALUES $sql;" ); // @codingStandardsIgnoreLine.
	}

	WC_Cache_Helper::invalidate_cache_group( 'taxes' );
}