Merge pull request #23268 from Spreeuw/patch-8
store tax rate percent in tax line items
This commit is contained in:
commit
60b385ea93
|
@ -557,6 +557,7 @@ class WC_Checkout {
|
|||
'rate_code' => WC_Tax::get_rate_code( $tax_rate_id ),
|
||||
'label' => WC_Tax::get_rate_label( $tax_rate_id ),
|
||||
'compound' => WC_Tax::is_compound( $tax_rate_id ),
|
||||
'rate_percent' => WC_Tax::get_rate_percent_value( $tax_rate_id ),
|
||||
)
|
||||
);
|
||||
|
||||
|
|
|
@ -27,6 +27,7 @@ class WC_Order_Item_Tax extends WC_Order_Item {
|
|||
'compound' => false,
|
||||
'tax_total' => 0,
|
||||
'shipping_tax_total' => 0,
|
||||
'rate_percent' => null,
|
||||
);
|
||||
|
||||
/*
|
||||
|
@ -98,6 +99,15 @@ class WC_Order_Item_Tax extends WC_Order_Item {
|
|||
$this->set_prop( 'compound', (bool) $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set rate value.
|
||||
*
|
||||
* @param float $value tax rate value.
|
||||
*/
|
||||
public function set_rate_percent( $value ) {
|
||||
$this->set_prop( 'rate_percent', (float) $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set properties based on passed in tax rate by ID.
|
||||
*
|
||||
|
@ -110,6 +120,7 @@ class WC_Order_Item_Tax extends WC_Order_Item {
|
|||
$this->set_rate_code( WC_Tax::get_rate_code( $tax_rate ) );
|
||||
$this->set_label( WC_Tax::get_rate_label( $tax_rate ) );
|
||||
$this->set_compound( WC_Tax::is_compound( $tax_rate ) );
|
||||
$this->set_rate_percent( WC_Tax::get_rate_percent_value( $tax_rate ) );
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -211,6 +222,16 @@ class WC_Order_Item_Tax extends WC_Order_Item {
|
|||
return $this->get_compound();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get rate value
|
||||
*
|
||||
* @param string $context What the value is for. Valid values are 'view' and 'edit'.
|
||||
* @return float
|
||||
*/
|
||||
public function get_rate_percent( $context = 'view' ) {
|
||||
return $this->get_prop( 'rate_percent', $context );
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Array Access Methods
|
||||
|
|
|
@ -655,19 +655,31 @@ class WC_Tax {
|
|||
* @return string
|
||||
*/
|
||||
public static function get_rate_percent( $key_or_rate ) {
|
||||
$rate_percent_value = self::get_rate_percent_value( $key_or_rate );
|
||||
$tax_rate_id = is_object( $key_or_rate ) ? $key_or_rate->tax_rate_id : $key_or_rate;
|
||||
return apply_filters( 'woocommerce_rate_percent', $rate_percent_value . '%', $tax_rate_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 ) ) {
|
||||
$key = $key_or_rate->tax_rate_id;
|
||||
$tax_rate = $key_or_rate->tax_rate;
|
||||
} else {
|
||||
$key = $key_or_rate;
|
||||
$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.
|
||||
*
|
||||
|
|
|
@ -22,7 +22,7 @@ class WC_Order_Item_Tax_Data_Store extends Abstract_WC_Order_Item_Type_Data_Stor
|
|||
* @since 3.0.0
|
||||
* @var array
|
||||
*/
|
||||
protected $internal_meta_keys = array( 'rate_id', 'label', 'compound', 'tax_amount', 'shipping_tax_amount' );
|
||||
protected $internal_meta_keys = array( 'rate_id', 'label', 'compound', 'tax_amount', 'shipping_tax_amount', 'rate_percent' );
|
||||
|
||||
/**
|
||||
* Read/populate data properties specific to this order item.
|
||||
|
@ -41,6 +41,7 @@ class WC_Order_Item_Tax_Data_Store extends Abstract_WC_Order_Item_Type_Data_Stor
|
|||
'compound' => get_metadata( 'order_item', $id, 'compound', true ),
|
||||
'tax_total' => get_metadata( 'order_item', $id, 'tax_amount', true ),
|
||||
'shipping_tax_total' => get_metadata( 'order_item', $id, 'shipping_tax_amount', true ),
|
||||
'rate_percent' => get_metadata( 'order_item', $id, 'rate_percent', true ),
|
||||
)
|
||||
);
|
||||
$item->set_object_read( true );
|
||||
|
@ -62,6 +63,7 @@ class WC_Order_Item_Tax_Data_Store extends Abstract_WC_Order_Item_Type_Data_Stor
|
|||
'compound' => 'compound',
|
||||
'tax_amount' => 'tax_total',
|
||||
'shipping_tax_amount' => 'shipping_tax_total',
|
||||
'rate_percent' => 'rate_percent',
|
||||
);
|
||||
$props_to_update = $this->get_props_to_update( $item, $meta_key_to_props, 'order_item' );
|
||||
|
||||
|
|
Loading…
Reference in New Issue