separate getter for rate percent & percent value

This commit is contained in:
Ewout Fernhout 2019-04-10 17:27:48 +02:00 committed by GitHub
parent 945ff7958f
commit 1ea6d7d3f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 1 deletions

View File

@ -679,6 +679,16 @@ class WC_Tax {
* @return string
*/
public static function get_rate_percent( $key_or_rate ) {
return apply_filters( 'woocommerce_rate_percent', self::get_rate_percent_value( $key_or_rate ) . '%', is_object( $key_or_rate ) ? $key_or_rate->tax_rate_id : $key_or_rate );
}
/**
* Return a given rates percent.
*
* @param mixed $key_or_rate Tax rate ID, or the db row itself in object format.
* @return float
*/
public static function get_rate_percent_value( $key_or_rate ) {
global $wpdb;
if ( is_object( $key_or_rate ) ) {
@ -689,9 +699,10 @@ class WC_Tax {
$tax_rate = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %s", $key ) );
}
return apply_filters( 'woocommerce_rate_percent', floatval( $tax_rate ) . '%', $key );
return floatval( $tax_rate );
}
/**
* Get a rates code. Code is made up of COUNTRY-STATE-NAME-Priority. E.g GB-VAT-1, US-AL-TAX-1.
*