From 1ea6d7d3f83abb6f5d89156bc20e2e316fb741eb Mon Sep 17 00:00:00 2001 From: Ewout Fernhout Date: Wed, 10 Apr 2019 17:27:48 +0200 Subject: [PATCH] separate getter for rate percent & percent value --- includes/class-wc-tax.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/includes/class-wc-tax.php b/includes/class-wc-tax.php index 18bd21f4f6e..e5201313e2c 100644 --- a/includes/class-wc-tax.php +++ b/includes/class-wc-tax.php @@ -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. *