From 47c3ba9d211bc8102e0125a842d387ee9dc4c27b Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Thu, 8 Oct 2015 17:24:37 -0300 Subject: [PATCH] Created WC_Tax::_get_tax_rate() method --- includes/api/class-wc-api-taxes.php | 28 ++++++++++++---------------- includes/class-wc-tax.php | 29 ++++++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 19 deletions(-) diff --git a/includes/api/class-wc-api-taxes.php b/includes/api/class-wc-api-taxes.php index 81a942e8434..7f409b403c8 100644 --- a/includes/api/class-wc-api-taxes.php +++ b/includes/api/class-wc-api-taxes.php @@ -129,29 +129,25 @@ class WC_API_Taxes extends WC_API_Resource { } // Get tax rate details - $tax = $wpdb->get_row( $wpdb->prepare( " - SELECT * - FROM {$wpdb->prefix}woocommerce_tax_rates - WHERE tax_rate_id = %d - ", $id ) ); + $tax = WC_Tax::_get_tax_rate( $id ); - if ( is_wp_error( $tax ) || is_null( $tax ) ) { + if ( is_wp_error( $tax ) || empty( $tax ) ) { throw new WC_API_Exception( 'woocommerce_api_invalid_tax_rate_id', __( 'A tax rate with the provided ID could not be found', 'woocommerce' ), 404 ); } $tax_data = array( - 'id' => $tax->tax_rate_id, - 'country' => $tax->tax_rate_country, - 'state' => $tax->tax_rate_state, + 'id' => $tax['tax_rate_id'], + 'country' => $tax['tax_rate_country'], + 'state' => $tax['tax_rate_state'], 'postcode' => '', 'city' => '', - 'rate' => $tax->tax_rate, - 'name' => $tax->tax_rate_name, - 'priority' => (int) $tax->tax_rate_priority, - 'compound' => (bool) $tax->tax_rate_compound, - 'shipping' => (bool) $tax->tax_rate_shipping, - 'order' => (int) $tax->tax_rate_order, - 'class' => $tax->tax_rate_class ? $tax->tax_rate_class : 'standard' + 'rate' => $tax['tax_rate'], + 'name' => $tax['tax_rate_name'], + 'priority' => (int) $tax['tax_rate_priority'], + 'compound' => (bool) $tax['tax_rate_compound'], + 'shipping' => (bool) $tax['tax_rate_shipping'], + 'order' => (int) $tax['tax_rate_order'], + 'class' => $tax['tax_rate_class'] ? $tax['tax_rate_class'] : 'standard' ); // Get locales from a tax rate diff --git a/includes/class-wc-tax.php b/includes/class-wc-tax.php index 348f0af3ea6..257cbcf0f16 100644 --- a/includes/class-wc-tax.php +++ b/includes/class-wc-tax.php @@ -682,7 +682,8 @@ class WC_Tax { * @access private * * @param array $tax_rate - * @return int tax rate id + * + * @return int tax rate id */ public static function _insert_tax_rate( $tax_rate ) { global $wpdb; @@ -694,6 +695,28 @@ class WC_Tax { return $wpdb->insert_id; } + /** + * Get tax rate + * + * Internal use only. + * + * @since 2.5.0 + * @access private + * + * @param int $tax_rate_id + * + * @return array + */ + public static function _get_tax_rate( $tax_rate_id ) { + global $wpdb; + + return $wpdb->get_row( $wpdb->prepare( " + SELECT * + FROM {$wpdb->prefix}woocommerce_tax_rates + WHERE tax_rate_id = %d + ", $tax_rate_id ), ARRAY_A ); + } + /** * Update a tax rate * @@ -702,8 +725,8 @@ class WC_Tax { * @since 2.3.0 * @access private * - * @param int $tax_rate_id - * @param array $tax_rate + * @param int $tax_rate_id + * @param array $tax_rate */ public static function _update_tax_rate( $tax_rate_id, $tax_rate ) { global $wpdb;