Created WC_Tax::_get_tax_rate() method

This commit is contained in:
Claudio Sanches 2015-10-08 17:24:37 -03:00
parent 1cded0e1a3
commit 47c3ba9d21
2 changed files with 38 additions and 19 deletions

View File

@ -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

View File

@ -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;