WC_Order_Item_Product::set_taxes()
Set line taxes and totals for passed in taxes.
Method of the class: WC_Order_Item_Product{}
No Hooks.
Return
null
. Nothing (null).
Usage
$WC_Order_Item_Product = new WC_Order_Item_Product(); $WC_Order_Item_Product->set_taxes( $raw_tax_data );
- $raw_tax_data(array) (required)
- Raw tax data.
WC_Order_Item_Product::set_taxes() WC Order Item Product::set taxes code WC 9.4.2
public function set_taxes( $raw_tax_data ) { $raw_tax_data = maybe_unserialize( $raw_tax_data ); $tax_data = array( 'total' => array(), 'subtotal' => array(), ); if ( ! empty( $raw_tax_data['total'] ) && ! empty( $raw_tax_data['subtotal'] ) ) { $tax_data['subtotal'] = array_map( 'wc_format_decimal', $raw_tax_data['subtotal'] ); $tax_data['total'] = array_map( 'wc_format_decimal', $raw_tax_data['total'] ); // Subtotal cannot be less than total! if ( NumberUtil::array_sum( $tax_data['subtotal'] ) < NumberUtil::array_sum( $tax_data['total'] ) ) { $tax_data['subtotal'] = $tax_data['total']; } } $this->set_prop( 'taxes', $tax_data ); if ( 'yes' === get_option( 'woocommerce_tax_round_at_subtotal' ) ) { $this->set_total_tax( NumberUtil::array_sum( $tax_data['total'] ) ); $this->set_subtotal_tax( NumberUtil::array_sum( $tax_data['subtotal'] ) ); } else { $this->set_total_tax( NumberUtil::array_sum( array_map( 'wc_round_tax_total', $tax_data['total'] ) ) ); $this->set_subtotal_tax( NumberUtil::array_sum( array_map( 'wc_round_tax_total', $tax_data['subtotal'] ) ) ); } }