subcriptioninfo.php 3.97 KB
<?php

function productAndTotalSubcription($subscription) {
    $newTotal = array();
    $has_refund = false;

    if ($total_refunded = $subscription->get_total_refunded()) {
        $has_refund = true;
    }
    if ($totals = $subscription->get_order_item_totals()) {
        foreach ($totals as $key => $total) {
            $value = $total['value'];

            // Check for refund
            if ($has_refund && 'order_total' === $key) {
                $refunded_tax_del = '';
                $refunded_tax_ins = '';

                // Tax for inclusive prices
                if (wc_tax_enabled() && 'incl' == $subscription->tax_display_cart) {

                    $tax_del_array = array();
                    $tax_ins_array = array();

                    if ('itemized' == get_option('woocommerce_tax_total_display')) {

                        foreach ($subscription->get_tax_totals() as $code => $tax) {
                            $tax_del_array[] = sprintf('%s %s', $tax->formatted_amount, $tax->label);
                            $tax_ins_array[] = sprintf('%s %s', wc_price($tax->amount - $subscription->get_total_tax_refunded_by_rate_id($tax->rate_id), array('currency' => $subscription->get_order_currency())), $tax->label);
                        }
                    } else {
                        $tax_del_array[] = sprintf('%s %s', wc_price($subscription->get_total_tax(), array('currency' => $subscription->get_order_currency())), WC()->countries->tax_or_vat());
                        $tax_ins_array[] = sprintf('%s %s', wc_price($subscription->get_total_tax() - $subscription->get_total_tax_refunded(), array('currency' => $subscription->get_order_currency())), WC()->countries->tax_or_vat());
                    }

                    if (!empty($tax_del_array)) {
                        // translators: placeholder is price string, denotes tax included in cart/order total
                        $refunded_tax_del .= ' ' . sprintf(_x('(Includes %s)', 'includes tax', 'woocommerce-subscriptions'), implode(', ', $tax_del_array));
                    }

                    if (!empty($tax_ins_array)) {
                        // translators: placeholder is price string, denotes tax included in cart/order total
                        $refunded_tax_ins .= ' ' . sprintf(_x('(Includes %s)', 'includes tax', 'woocommerce-subscriptions'), implode(', ', $tax_ins_array));
                    }
                }

                $value = '<del>' . strip_tags($subscription->get_formatted_order_total()) . $refunded_tax_del . '</del> <ins>' . wc_price($subscription->get_total() - $total_refunded, array('currency' => $subscription->get_order_currency())) . $refunded_tax_ins . '</ins>';
            }
            $newTotal[$key] = array('label' => $total['label'], 'value' => $value);
        }
    }
// Check for refund
    if ($has_refund) {
        $newTotal['refuned'] = array('label' => esc_html_e('Refunded:', 'woocommerce-subscriptions'), 'value' => '-' . wp_kses_post(wc_price($total_refunded, array('currency' => $subscription->get_order_currency()))));
    }
    return $newTotal;
}

function getProductInfo($subscription) {
    $productItems = array();
    if (sizeof($subscription->get_items()) > 0) {
        $i = 0;
        foreach ($subscription->get_items() as $item_id => $item) {
           
            $_product = apply_filters('woocommerce_subscriptions_order_item_product', $subscription->get_product_from_item($item), $item);
            //if ($_product && !$_product->is_visible()) {
            $productItems[$i]['name'] = esc_html(apply_filters('woocommerce_order_item_name', $item['name'], $item));
//            } else {
//                echo wp_kses_post(apply_filters('woocommerce_order_item_name', sprintf('<a href="%s">%s</a>', get_permalink($item['product_id']), $item['name']), $item));
//            }

            $productItems[$i]['qty'] = wp_kses_post(apply_filters('woocommerce_order_item_quantity_html', $item['qty'], $item));
            $i++;
        }
    }
    return $productItems;
}
?>