Thank you for order: price without VAT wrong

<?php
if (class_exists('tzn_thankyou')) {
    remove_action('tzn_thankyou_right_col', [tzn_thankyou(), 'display_order_total'], 30);
    add_action('tzn_thankyou_right_col', 'tzn_thankyou_right_col_custom', 30);
    function tzn_thankyou_right_col_custom($id)
    {
        $object = wc_get_order($id);
        $cart_style = get_theme_mod('header_cart_style', 'dropdown');
        $order_page = (is_wc_endpoint_url('order-received') ? true : false);
        if($order_page ){
            $cart_subtotal_thankyou_page = $object->get_order_item_totals()['cart_subtotal']['value'];
        }
        
        $subtotal    = ($order_page ? $cart_subtotal_thankyou_page : $object->get_cart_subtotal());
        $tax_display = isset($tax_display) ? $tax_display : get_option('woocommerce_tax_display_cart');
        $shipping = 0;
        if (wc_shipping_enabled()) {
            $shipping = ('excl' === $tax_display ? wc_price($object->get_shipping_total()) : wc_price($object->get_shipping_total() + $object->get_shipping_tax()));
        }
        echo '<div class="cart_totals totals-container' . (WC()->customer->has_calculated_shipping() ? ' calculated_shipping' : '') . '">';

        $is_mini_cart = isset($is_mini_cart) ? $is_mini_cart : false;

        $tzn_options = tzn_admin()->get_options();
        $tzn_options_shop = $tzn_options[tzn_constants::SHOP] ?? [];


        $include_shipping_taxes = isset($tzn_options_shop['include_shipping_tax']) ? (int) $tzn_options_shop['include_shipping_tax'] : false;
        $show_tip = isset($tzn_options_shop['show_tip']) ? (int) $tzn_options_shop['show_tip'] : false;
        $show_coupons = isset($tzn_options_shop['mini_cart']['show_coupons']) ? (int) $tzn_options_shop['mini_cart']['show_coupons'] : false;

        // always show if not in minicart
        if (!$is_mini_cart) {
            $show_coupons = true;
        }
        ?>
        <div class="inner-container">
            <?php do_action('woocommerce_before_cart_totals'); ?>
            <div class="subtotal values">
                <div class="total-title"><?php _e('Subtotal', 'woocommerce'); ?></div>
                <?php echo $subtotal; ?>
            </div>

            <?php
            if ($is_mini_cart) {
                tzn_checkout()->getLegalInfo();
            }
            ?>

            <?php
            if (!$is_mini_cart) {
                if (WC()->cart->needs_shipping() && WC()->cart->show_shipping()) {
                    ?>

                    <?php do_action('woocommerce_cart_totals_before_shipping'); ?>
                    <?php
                    if (!is_checkout()) {
                        $shipping_packages = WC()->shipping()->get_packages();
                        if (!$shipping_packages) {
                            WC()->cart->calculate_shipping();
                        }
                        /**
                         * you can manually call subscription shipping html function in the hooks below if it's needed
                         *
                         * if ( class_exists('WC_Subscriptions_Cart') &&
                         *      WC_Subscriptions_Cart::cart_contains_subscription() &&
                         *      function_exists('wcs_cart_totals_shipping_html') &&
                         *      isset(WC()->cart->recurring_carts) &&
                         *      is_countable(WC()->cart->recurring_carts)) {
                         * // do some stuff...
                         * }
                         */
                        ob_start();
                        wc_cart_totals_shipping_html();
                        $shipping_html = ob_get_clean();
                        /**
                         * take a look on the hook (tzn_checkout_shipping_html) in the class-checkout.php
                         */
                        $shipping_html = apply_filters('tzn_container_totals_shipping_html', $shipping_html);
                        /**
                         * global hook if the required action is the same for both
                         */
                        $shipping_html = apply_filters('tzn_cart_totals_shipping_html', $shipping_html);
                        echo $shipping_html;
                    } else {
                        echo '<div class="shipping values">
                <div class="total-title">' . __('Shipping fee', 'tzn') . '</div>
                ' . $shipping . '
                </div>';
                    } ?>
                    <?php do_action('woocommerce_cart_totals_after_shipping'); ?>

                    <?php if (!is_checkout() && 'yes' === get_option('woocommerce_enable_shipping_calc')) {
                        woocommerce_shipping_calculator();
                    }
                    do_action('tzn_shopkit_after_shipping_details');
                }
                //show shipping in thankyou
                if (is_wc_endpoint_url('order-received') && wc_shipping_enabled()) {
                    echo '<div class="shipping values">
                <div class="total-title">' . __('Shipping fee', 'tzn') . '</div>
                ' . $shipping . '
                </div>';
                }
            }

            if (!$is_mini_cart) {
                /**
                 * @var $fee WC_Order_Item_Fee
                 */
                foreach ($object->get_fees() as $fee) {
                    $cart_totals_fee_html = WC()->cart->display_prices_including_tax() ? wc_price((isset($fee->total) ? $fee->total : 0) + (isset($fee->tax) ? $fee->tax : 0)) : wc_price((isset($fee->total) ? $fee->total : 0));
                    $fee_html = apply_filters('woocommerce_cart_totals_fee_html', $cart_totals_fee_html, $fee);
                    if (is_wc_endpoint_url('order-received')) {
                        $fee_name = $fee->get_name();
                        $fee_amount = wc_price($fee->get_total());
                    } else {
                        $fee_name = isset($fee->name) ? $fee->name : '';
                        $fee_amount = $fee_html;
                    }
                    ?>
                    <div class="fee values">
                        <div class="total-title">
                            <?php echo esc_html($fee_name); ?>
                            <?php
                            if ($show_tip && ($fee_name === __('Tip', 'tzn')) && WC()->session->__isset(tzn_constants::SESSION_TIP_AMOUNT)) {
                                $nonce = wp_create_nonce('action_remove_tip');
                                ?>
                                <a href="" class="remove-tip">
                                    <input id="_tip_nonce" name="_tip_nonce" type="hidden" value="<?php esc_attr_e($nonce); ?>">
                                    <i class="fas fa-times-circle"></i>
                                </a>
                                <?php
                            }
                            ?>
                        </div>
                        <span><?php echo $fee_amount; ?></span>
                    </div>
                    <?php
                }
            }


            if (!is_wc_endpoint_url('order-received')) {
                /* Taxes */
                if (!$is_mini_cart) {
                    if (wc_tax_enabled()) {
                        if (class_exists('WooCommerce_Germanized')) {
                            $include_shipping_taxes = apply_filters('tzn_gzd_cart_include_shipping_taxes', $include_shipping_taxes);

                            foreach (wc_gzd_get_cart_taxes($object, $include_shipping_taxes) as $tax) {
                                $label = wc_gzd_get_tax_rate_label($tax['tax']->rate);
                                ?>
                                <div class="vat values" data-vat="<?php echo $tax['amount']; ?>">
                                    <div class="total-title"><?php echo $label; ?></div>
                                    <div data-title="<?php echo esc_attr($label); ?>"><?php echo wc_price($tax['amount']); ?></div>
                                </div>
                                <?php
                            }
                            //fix for germanized when settings are excluding tax
                            if ('excl' === wc_gzd_get_cart_tax_display_mode()) {
                                $taxes = $object->get_tax_totals();
                                foreach ($taxes as $code => $tax) {
                                    ?>
                                    <div class="vat values" data-vat="<?php echo $tax->amount; ?>">
                                        <div class="total-title"><?php echo $tax->label; ?></div>
                                        <div data-title="<?php echo esc_attr($tax->label); ?>"><?php echo wc_price($tax->amount); ?>
                                        </div>
                                    </div>
                                    <?php
                                }
                            }
                        } else {
                            $taxes = $object->get_tax_totals();
                            foreach ($taxes as $code => $tax) {

                                if (!isset($tax_array[$tax->rate])) {
                                    $tax_array[$tax->rate] = array(
                                        'tax' => $tax,
                                        'amount' => $tax->amount,
                                        'contains' => array($tax)
                                    );
                                } ?>
                                <div class="vat values" data-vat="<?php echo $tax['amount']; ?>">
                                    <div class="total-title"><?php __('VAT', 'tzn'); ?></div>
                                    <div><?php echo wc_price($tax['amount']); ?>
                                    </div>
                                </div>
                            <?php }
                        }

                    }
                }
                /* Coupons */
                if ($show_coupons) {
                    foreach ($object->get_applied_coupons() as $coupon_code) {

                        $valid = true;
                        $coupon = new WC_Coupon($coupon_code);

                        if ($object instanceof WC_Cart) {
                            $discounts = new WC_Discounts($object);
                            $valid = $discounts->is_coupon_valid($coupon);

                            if (is_wp_error($valid)) {
                                $valid = false;
                            }

                            if (!$valid) {
                                $object->remove_coupon($coupon_code);
                                wc_clear_notices();
                                $object->calculate_totals();
                            }
                        }

                        if ($valid && $coupon instanceof WC_Coupon) {
                            $coupon_code = $coupon->get_code();
                            $discount_amount = $object->get_coupon_discount_amount($coupon_code, $ex_tax = false);
                            $discount_amount_text = '-' . wc_price($discount_amount);
                            $discount_amount_text = apply_filters('tzn_woocommerce_cart_totals_discount_amount', $discount_amount_text, $discount_amount, $coupon_code);
                            ?>
                            <div class="coupon values">
                                <strong class="total-title"><?php echo esc_html($coupon_code); ?>
                                    <?php if (is_callable('Points_Rewards_For_WooCommerce_Public', 'wps_wpr_par_virtual_coupon_remove')) { ?>
                                        <a href="<?php echo esc_url(add_query_arg('remove_coupon', urlencode($coupon->get_code()), defined('WOOCOMMERCE_CHECKOUT') ? wc_get_checkout_url() : wc_get_cart_url())); ?>"
                                            class="wps_remove_virtual_coupon" data-coupon="<?php esc_attr($coupon->get_code()); ?>">
                                            <i class="fas fa-times-circle"></i>
                                        </a>
                                    <?php } else { ?>
                                        <a href="" class="woocommerce-remove-coupon" data-coupon="<?php echo $coupon_code; ?>">
                                            <i class="fas fa-times-circle"></i>
                                        </a>
                                    <?php } ?>
                                </strong>
                                <span><?php echo $discount_amount_text; ?></span>
                            </div>
                            <?php
                        }
                    }
                }
                ?>
            <?php //ORDER RECEIVED
            } elseif (is_wc_endpoint_url('order-received')) {
                $tzn_order = tzn_order();
                echo $tzn_order->get_order_taxes_html($object);
                if ($object->get_discount_total()) {
                    ?>
                    <div class="coupon values">
                        <div class="total-title">
                            <?php _e('Voucher / Discount', 'tzn'); ?></span><span>
                                <?php //echo '-' . wc_price($object->get_discount_total())
                                                echo '-' . wc_price($object->get_total_discount()); ?></span>
                        </div>
                        <?php
                }

            }
            echo '</div>';
            wc_get_template(
                'global/grand-total.php',
                array(
                    'object' => $object,
                )
            );
            ?>
                <?php do_action('woocommerce_after_cart_totals'); ?>
            </div>
            <?php
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *