Merge pull request #13253 from woocommerce/fix-13249

Order Item Tax set_rate fixes
This commit is contained in:
Mike Jolley 2017-02-21 09:55:22 +00:00 committed by GitHub
commit 55ad57ff3a
2 changed files with 17 additions and 6 deletions

View File

@ -104,10 +104,12 @@ class WC_Order_Item_Tax extends WC_Order_Item {
* @throws WC_Data_Exception * @throws WC_Data_Exception
*/ */
public function set_rate( $tax_rate_id ) { public function set_rate( $tax_rate_id ) {
$tax_rate = WC_Tax::_get_tax_rate( $tax_rate_id, OBJECT );
$this->set_rate_id( $tax_rate_id ); $this->set_rate_id( $tax_rate_id );
$this->set_rate_code( WC_Tax::get_rate_code( $tax_rate_id ) ); $this->set_rate_code( WC_Tax::get_rate_code( $tax_rate ) );
$this->set_label( WC_Tax::get_rate_code( $tax_rate_id ) ); $this->set_label( WC_Tax::get_rate_label( $tax_rate ) );
$this->set_compound( WC_Tax::get_rate_code( $tax_rate_id ) ); $this->set_compound( WC_Tax::is_compound( $tax_rate ) );
} }
/* /*

View File

@ -594,12 +594,21 @@ class WC_Tax {
/** /**
* Return true/false depending on if a rate is a compound rate. * Return true/false depending on if a rate is a compound rate.
* *
* @param int key * @param mixed $key_or_rate Tax rate ID, or the db row itself in object format
* @return bool * @return bool
*/ */
public static function is_compound( $key ) { public static function is_compound( $key_or_rate ) {
global $wpdb; global $wpdb;
return $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate_compound FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %s", $key ) ) ? true : false;
if ( is_object( $key_or_rate ) ) {
$key = $key_or_rate->tax_rate_id;
$compound = $key_or_rate->tax_rate_compound;
} else {
$key = $key_or_rate;
$compound = $wpdb->get_var( $wpdb->prepare( "SELECT tax_rate_compound FROM {$wpdb->prefix}woocommerce_tax_rates WHERE tax_rate_id = %s", $key ) ) ? true : false;
}
return (bool) apply_filters( 'woocommerce_rate_compound', $compound, $key );
} }
/** /**