/** * Gets a product's tax description (if is taxable) * * @return mixed string if is taxable else returns false */ public function get_tax_info() { $_tax = new WC_Tax(); $tax_notice = false; if ($this->is_taxable()) { $tax_display_mode = get_option('woocommerce_tax_display_shop'); $tax_rates = $_tax->get_rates($this->get_tax_class()); if (!empty($tax_rates)) { $tax_rates = array_values($tax_rates); // If is variable or is virtual vat exception dont show exact tax rate if ($this->is_virtual_vat_exception() || $this->is_type('variable')) { $tax_notice = $tax_display_mode == 'incl' && !WC()->customer->is_vat_exempt() ? __('incl. VAT', 'woocommerce-germanized') : __('excl. VAT', 'woocommerce-germanized'); } else { $tax_notice = $tax_display_mode == 'incl' && !WC()->customer->is_vat_exempt() ? sprintf(__('incl. %s%% VAT', 'woocommerce-germanized'), wc_gzd_format_tax_rate_percentage($tax_rates[0]['rate'])) : sprintf(__('excl. %s%% VAT', 'woocommerce-germanized'), wc_gzd_format_tax_rate_percentage($tax_rates[0]['rate'])); } } } return apply_filters('woocommerce_gzd_product_tax_info', $tax_notice, $this); }
/** * Improve tax display within order totals * * @param array $order_totals * @param object $order * @return array */ public function order_item_totals($order_totals, $order) { // Set to formatted total without displaying tax info behind the price $order_totals['order_total']['value'] = $order->get_formatted_order_total(); // Tax for inclusive prices if ('yes' == get_option('woocommerce_calc_taxes') && 'incl' == $order->tax_display_cart) { $tax_array = array(); if ('itemized' == get_option('woocommerce_tax_total_display')) { foreach ($order->get_tax_totals() as $code => $tax) { $tax->rate = WC_Tax::get_rate_percent($tax->rate_id); if (!isset($tax_array[$tax->rate])) { $tax_array[$tax->rate] = array('tax' => $tax, 'amount' => $tax->amount, 'contains' => array($tax)); } else { array_push($tax_array[$tax->rate]['contains'], $tax); $tax_array[$tax->rate]['amount'] += $tax->amount; } } } else { $base_rate = array_values(WC_Tax::get_shop_base_rate()); $base_rate = (object) $base_rate[0]; $base_rate->rate = $base_rate->rate; $tax_array[] = array('tax' => $base_rate, 'contains' => array($base_rate), 'amount' => $order->get_total_tax()); } if (!empty($tax_array)) { foreach ($tax_array as $tax) { $order_totals['tax_' . $tax['tax']->label] = array('label' => '<span class="tax small tax-label">' . (get_option('woocommerce_tax_total_display') == 'itemized' ? sprintf(__('incl. %s%% VAT', 'woocommerce-germanized'), wc_gzd_format_tax_rate_percentage($tax['tax']->rate)) : __('incl. VAT', 'woocommerce-germanized')) . '</span>', 'value' => '<span class="tax small tax-value">' . wc_price($tax['amount']) . '</span>'); } } } return $order_totals; }
/** * Get order total tax html. * * @return void */ function wc_gzd_cart_totals_order_total_tax_html() { $_tax = new WC_Tax(); // If prices are tax inclusive, show taxes here if (get_option('woocommerce_calc_taxes') == 'yes' && WC()->cart->tax_display_cart == 'incl') { $tax_array = array(); if (get_option('woocommerce_tax_total_display') == 'itemized') { foreach (WC()->cart->get_tax_totals() as $code => $tax) { $rate = wc_gzd_get_tax_rate($tax->tax_rate_id); if (!$rate) { continue; } if (!empty($rate) && isset($rate->tax_rate)) { $tax->rate = $rate->tax_rate; } if (!isset($tax_array[$tax->rate])) { $tax_array[$tax->rate] = array('tax' => $tax, 'amount' => $tax->amount, 'contains' => array($tax)); } else { array_push($tax_array[$tax->rate]['contains'], $tax); $tax_array[$tax->rate]['amount'] += $tax->amount; } } } else { $base_rate = array_values(WC_Tax::get_shop_base_rate()); $base_rate = (object) $base_rate[0]; $base_rate->rate = $base_rate->rate; $tax_array[] = array('tax' => $base_rate, 'contains' => array($base_rate), 'amount' => WC()->cart->get_taxes_total(true, true)); } if (!empty($tax_array)) { foreach ($tax_array as $tax) { echo ' <tr class="order-tax"> <th>' . (get_option('woocommerce_tax_total_display') == 'itemized' ? sprintf(__('incl. %s%% VAT', 'woocommerce-germanized'), wc_gzd_format_tax_rate_percentage($tax['tax']->rate)) : __('incl. VAT', 'woocommerce-germanized')) . '</th> <td>' . wc_price($tax['amount']) . '</td> </tr>'; } } } }
/** * Gets a product's tax description (if is taxable) * * @return mixed string if is taxable else returns false */ public function get_tax_info() { $_tax = new WC_Tax(); if ($this->is_taxable()) { $tax_display_mode = get_option('woocommerce_tax_display_shop'); $tax_rates = $_tax->get_rates($this->get_tax_class()); if (!empty($tax_rates)) { $tax_rates = array_values($tax_rates); // If is variable or is virtual vat exception dont show exact tax rate if ($this->is_virtual_vat_exception() || $this->is_type('variable')) { return $tax_display_mode == 'incl' ? __('incl. VAT', 'woocommerce-germanized') : __('excl. VAT', 'woocommerce-germanized'); } return $tax_display_mode == 'incl' ? sprintf(__('incl. %s%% VAT', 'woocommerce-germanized'), wc_gzd_format_tax_rate_percentage($tax_rates[0]['rate'])) : sprintf(__('excl. %s%% VAT', 'woocommerce-germanized'), wc_gzd_format_tax_rate_percentage($tax_rates[0]['rate'])); } } return false; }