diff --git a/includes/class-wc-order-item-tax.php b/includes/class-wc-order-item-tax.php index 20bcb741b5c..38f2761abc9 100644 --- a/includes/class-wc-order-item-tax.php +++ b/includes/class-wc-order-item-tax.php @@ -27,6 +27,7 @@ class WC_Order_Item_Tax extends WC_Order_Item { 'compound' => false, 'tax_total' => 0, 'shipping_tax_total' => 0, + 'rate_percent' => 0.0, ); /* @@ -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 diff --git a/includes/data-stores/class-wc-order-item-tax-data-store.php b/includes/data-stores/class-wc-order-item-tax-data-store.php index 6a9793dbb1c..ab5325a6e88 100644 --- a/includes/data-stores/class-wc-order-item-tax-data-store.php +++ b/includes/data-stores/class-wc-order-item-tax-data-store.php @@ -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' );