Order=$order; $this->Taxes=$this->GetTaxes(); $this->LineItems=$lineItems; $this->Item=$item; $this->CalculateTaxes($this->LineItems); } private function CalculateTaxes($lineItems) { $tax_based_on = get_option( 'woocommerce_tax_based_on' ); if ( $tax_based_on=='billing') { $country = $this->Order->get_billing_country(); $state = $this->Order->get_billing_state(); $postcode = $this->Order->get_billing_postcode(); $city = $this->Order->get_billing_city(); } elseif ( 'shipping' === $tax_based_on ) { $country = $this->Order->get_shipping_country(); $state = $this->Order->get_shipping_state(); $postcode = $this->Order->get_shipping_postcode(); $city = $this->Order->get_shipping_city(); } if($tax_based_on==='base'||empty($country)) { $default = wc_get_base_location(); $country = $default['country']; $state = $default['state']; $postcode = ''; $city = ''; } $tax_class = $this->Item->get_tax_class(); $tax_rates = \WC_Tax::find_rates( array( 'country' => $country, 'state' => $state, 'postcode' => $postcode, 'city' => $city, 'tax_class' => $tax_class ) ); $taxes=$this->Order->get_taxes(); foreach($lineItems as $lineItem) { if($lineItem->Type=='grouppanel'||$lineItem->Type=='collapsible'||$lineItem->Type=='globalcontainer'||$lineItem->Type=='popup') { $this->CalculateTaxes($lineItem->Value); }else if($lineItem->Type=='repeater') { foreach($lineItem->Value as &$repeaterItem) $this->CalculateTaxes($repeaterItem); }else /* if(isset($lineItem->SelectedValues)) { foreach($lineItem->SelectedValues as $subLineItem) { $this->AddTaxes($subLineItem, $taxes, $tax_rates); } }else*/ $this->AddTaxes($lineItem, $taxes, $tax_rates); } } /** * @param LineItemDTO $field * @param array $taxes * @param $tax_rates */ private function AddTaxes($field, array $taxes,$tax_rates) { $field->Taxes=array(); $field->TotalTax=0; $totalTax=0; /** @var WC_Order_Item_Tax $currentTax */ $rates=[]; if(isset($field->Price)&&\is_numeric($field->Price)) $rates = \WC_Tax::calc_tax($field->Price, $tax_rates,$this->Order->get_prices_include_tax()); foreach($taxes as $currentTax) { $taxToUse=(object)array('Price'=>0,'Name' => $currentTax->get_label(),); foreach ($rates as $key => $value) { $field->TotalTax += $value; if ($currentTax->get_rate_id() == $key) { $taxToUse = (object)array('Name' => $currentTax->get_label(), 'Price' => $value); } } $field->Taxes[]=$taxToUse; } } public function Execute() { $this->CreateRow(); } private function CreateRow() { $currency=array( 'Format'=>get_woocommerce_price_format(), 'Decimals'=>wc_get_price_decimals(), 'ThousandSeparator'=>wc_get_price_thousand_separator(), 'DecimalSeparator'=>wc_get_price_decimal_separator(), 'Symbol'=>get_woocommerce_currency_symbol(), ); $nonce=\wp_create_nonce('rednaowooextraproduct_order_designer'); $variableId="rnExtraProductOptions".$this->Item->get_id(); echo ''; echo '
'; echo '
'.__("Loading Items").'
|
".\esc_html($item->Label)."
|
".\esc_html($item->Value)."
|