Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action ( 'wcfm_order_totals_after_total', function() {
- global $WCFM;
- remove_action ( 'wcfm_order_totals_after_total', array( $WCFM->wcfm_marketplace, 'wcfmmp_order_total_commission' ) );
- add_action ( 'wcfm_order_totals_after_total', 'wcfmmp_order_total_commission', 11 );
- }, 9 );
- // WCFM Marketplace Order Total Commission
- function wcfmmp_order_total_commission($order_id)
- {
- global $WCFM, $wpdb, $WCFMmp;
- $admin_fee_mode = apply_filters('wcfm_is_admin_fee_mode', false);
- $gross_sale_order = $WCFM->wcfm_vendor_support->wcfm_get_gross_sales_by_vendor($WCFM->wcfm_marketplace->vendor_id, '', '', $order_id);
- $order = wc_get_order($order_id);
- $order_currency = $order->get_currency();
- $order_status = sanitize_title($order->get_status());
- $td_style = '';
- $sql = "SELECT
- GROUP_CONCAT(ID) as commission_ids,
- GROUP_CONCAT(item_id) as order_item_ids,
- SUM(commission_amount) as line_total,
- SUM(total_commission) as total_commission,
- SUM(item_total) as item_total,
- SUM(item_sub_total) as item_sub_total,
- SUM(shipping) as shipping,
- SUM(tax) as tax,
- SUM(shipping_tax_amount) as shipping_tax_amount,
- SUM(refunded_amount) as refunded_amount,
- SUM(discount_amount) as discount_amount
- FROM
- {$wpdb->prefix}wcfm_marketplace_orders
- WHERE
- order_id = % d
- AND `vendor_id` = % d
- AND `is_refunded` != 1
- ";
- $order_due = $wpdb->get_results($wpdb->prepare($sql, $order_id, $WCFM->wcfm_marketplace->vendor_id));
- if (!$order_due || !isset($order_due[0])) return;
- $total = 0;
- $subtotal = 0;
- $calculated_total = 0;
- $total_tax = 0;
- $total_shipping = 0;
- $shipping_tax = 0;
- $refund_total = 0;
- $discount_total = 0;
- $commission_tax = 0;
- $aff_commission = 0;
- $transaction_charge = 0;
- $commission_rule = array();
- $aff_commission_rule = array();
- $total = $order_due[0]->total_commission;
- if ($WCFMmp->wcfmmp_vendor->is_vendor_deduct_discount($WCFM->wcfm_marketplace->vendor_id, $order_id)) {
- $calculated_total = $order_due[0]->item_total;
- } else {
- $calculated_total = $order_due[0]->item_sub_total;
- }
- //$calculated_total += ( float ) $order_due[0]->tax;
- // WC Refund Support - 3.0.4
- $commission_ids = explode(",", $order_due[0]->commission_ids);
- foreach ($commission_ids as $commission_id) {
- if (method_exists($WCFMmp->wcfmmp_commission, 'wcfmmp_get_commission_meta')) {
- $total_tax += (float) $WCFMmp->wcfmmp_commission->wcfmmp_get_commission_meta($commission_id, 'gross_tax_cost');
- $total_shipping += (float) $WCFMmp->wcfmmp_commission->wcfmmp_get_commission_meta($commission_id, 'gross_shipping_cost');
- $shipping_tax += (float) $WCFMmp->wcfmmp_commission->wcfmmp_get_commission_meta($commission_id, 'gross_shipping_tax');
- $commission_tax += (float) $WCFMmp->wcfmmp_commission->wcfmmp_get_commission_meta($commission_id, 'commission_tax');
- $aff_commission += (float) $WCFMmp->wcfmmp_commission->wcfmmp_get_commission_meta($commission_id, '_wcfm_affiliate_commission');
- $transaction_charge += (float) $WCFMmp->wcfmmp_commission->wcfmmp_get_commission_meta($commission_id, 'transaction_charge');
- $commission_rule = unserialize($WCFMmp->wcfmmp_commission->wcfmmp_get_commission_meta($commission_id, 'commission_rule'));
- //$aff_commission_rule = unserialize( $WCFMmp->wcfmmp_commission->wcfmmp_get_commission_meta( $commission_id, '_wcfm_affiliate_commission_rule' ) );
- }
- }
- //print_r($commission_rule );
- //print_r($aff_commission_rule);
- $calculated_total += (float) $total_tax;
- $calculated_total += (float) apply_filters('wcfmmmp_gross_sales_shipping_cost', $total_shipping, $WCFM->wcfm_marketplace->vendor_id);
- $calculated_total += (float) $shipping_tax;
- $refund_total = $order_due[0]->refunded_amount;
- $discount_total = $order_due[0]->discount_amount;
- if ($get_shipping = $WCFMmp->wcfmmp_vendor->is_vendor_get_shipping($WCFM->wcfm_marketplace->vendor_id)) {
- //$total += ( float ) $order_due[0]->shipping;
- }
- if ($get_tax = $WCFMmp->wcfmmp_vendor->is_vendor_get_tax($WCFM->wcfm_marketplace->vendor_id)) {
- //$total += (float) $order_due[0]->tax;
- if ($get_shipping) {
- //$total += ( float ) $order_due[0]->shipping_tax_amount;
- }
- }
- ?>
- <?php //if( !$admin_fee_mode ) {
- ?>
- <?php do_action('wcfm_vendor_order_details_before_subtotal', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <tr>
- <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php esc_html_e('Subtotal', 'wc-frontend-manager'); ?>:</th>
- <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
- <div class="view">
- <?php
- $subtotal = $calculated_total - ((float) $refund_total + (float) $order_due[0]->shipping + (float) $order_due[0]->tax + (float) $order_due[0]->shipping_tax_amount);
- if ($refund_total && (round($subtotal, 2) != round($order_due[0]->item_sub_total, 2))) {
- echo "<del>" . wc_price($order_due[0]->item_sub_total, array('currency' => $order_currency)) . "</del>";
- echo "<ins>" . wc_price($subtotal, array('currency' => $order_currency)) . "</ins>";
- } else {
- echo wc_price($order_due[0]->item_sub_total, array('currency' => $order_currency));
- }
- ?>
- </div>
- </td>
- </tr>
- <?php do_action('wcfm_vendor_order_details_after_subtotal', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <?php //}
- ?>
- <?php if ($get_tax) { ?>
- <?php
- if (apply_filters('wcfm_is_allow_vendor_order_details_tax_breakup', false)) {
- $order_taxes = $order->get_taxes();
- $tax_breakups = array();
- if (!empty($order_taxes)) {
- foreach ($order_taxes as $tax_id => $tax_item) {
- $column_label = !empty($tax_item['label']) ? $tax_item['label'] : __('Tax', 'wc-frontend-manager');
- $tax_breakups[$tax_item->get_rate_id()] = array('label' => $column_label, 'subtotal' => 0, 'total' => 0);
- }
- }
- if (!empty($tax_breakups)) {
- $order_item_ids = explode(",", $order_due[0]->order_item_ids);
- foreach ($order_item_ids as $order_item_id) {
- $line_item = new WC_Order_Item_Product($order_item_id);
- if ($tax_data = $line_item->get_taxes()) {
- foreach ($order_taxes as $tax_item) {
- $tax_item_id = $tax_item->get_rate_id();
- $tax_item_total = isset($tax_data['total'][$tax_item_id]) ? $tax_data['total'][$tax_item_id] : 0;
- $tax_item_subtotal = isset($tax_data['subtotal'][$tax_item_id]) ? $tax_data['subtotal'][$tax_item_id] : 0;
- if (isset($tax_breakups[$tax_item_id])) {
- $tax_breakups[$tax_item_id]['subtotal'] += (float)$tax_item_subtotal;
- $tax_breakups[$tax_item_id]['total'] += (float)$tax_item_total;
- }
- }
- }
- }
- do_action('wcfm_vendor_order_details_before_tax_breakup', $order_id, $WCFM->wcfm_marketplace->vendor_id);
- foreach ($tax_breakups as $tax_breakup_is => $tax_breakup) {
- ?>
- <tr>
- <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php echo esc_html($tax_breakup['label']); ?>:</th>
- <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
- <div class="view">
- <?php
- if (apply_filters('wcfm_is_allow_vendor_order_details_commission_on_tax', false) && (round($tax_breakup['total'], 2) != round($tax_breakup['subtotal'], 2))) {
- echo "<del>" . wc_price($tax_breakup['total'], array('currency' => $order_currency)) . "</del>";
- echo "<ins>" . wc_price($tax_breakup['subtotal'], array('currency' => $order_currency)) . "</ins>";
- } else {
- echo wc_price($tax_breakup['subtotal'], array('currency' => $order_currency));
- }
- ?>
- </div>
- </td>
- </tr>
- <?php
- }
- do_action('wcfm_vendor_order_details_after_tax_breakup', $order_id, $WCFM->wcfm_marketplace->vendor_id);
- }
- }
- ?>
- <?php if (apply_filters('wcfm_is_allow_vendor_order_details_tax_breakup_total', true)) { ?>
- <?php do_action('wcfm_vendor_order_details_before_tax', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <tr>
- <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>">
- <?php if (apply_filters('wcfm_is_allow_vendor_order_details_tax_breakup', false)) {
- echo esc_html__('Total', 'wc-frontend-manager') . ' ';
- } ?>
- <?php esc_html_e('Tax', 'wc-frontend-manager'); ?>:
- </th>
- <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
- <div class="view">
- <?php
- if (apply_filters('wcfm_is_allow_vendor_order_details_commission_on_tax', false) && (round($total_tax, 2) != round($order_due[0]->tax, 2))) {
- echo "<del>" . wc_price($total_tax, array('currency' => $order_currency)) . "</del>";
- echo "<ins>" . wc_price($order_due[0]->tax, array('currency' => $order_currency)) . "</ins>";
- } else {
- echo wc_price($order_due[0]->tax, array('currency' => $order_currency));
- }
- ?>
- </div>
- </td>
- </tr>
- <?php do_action('wcfm_vendor_order_details_after_tax', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <?php } ?>
- <?php } ?>
- <?php if ($get_shipping && $order->get_formatted_shipping_address()) { ?>
- <?php do_action('wcfm_vendor_order_details_before_shipping', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <tr>
- <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php esc_html_e('Shipping', 'wc-frontend-manager'); ?>:</th>
- <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
- <div class="view">
- <?php
- if (apply_filters('wcfm_is_allow_vendor_order_details_commission_on_shipping', false) && (round($total_shipping, 2) != round($order_due[0]->shipping, 2))) {
- echo "<del>" . wc_price($total_shipping, array('currency' => $order_currency)) . "</del>";
- echo "<ins>" . wc_price($order_due[0]->shipping, array('currency' => $order_currency)) . "</ins>";
- } else {
- echo wc_price(apply_filters('wcfmmmp_gross_sales_shipping_cost', $order_due[0]->shipping, $WCFM->wcfm_marketplace->vendor_id), array('currency' => $order_currency));
- }
- ?>
- </div>
- </td>
- </tr>
- <?php do_action('wcfm_vendor_order_details_after_shipping', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <?php if ($get_tax) { ?>
- <?php
- if (apply_filters('wcfm_is_allow_vendor_order_details_tax_breakup', false)) {
- $order_taxes = $order->get_taxes();
- $tax_breakups = array();
- if (!empty($order_taxes)) {
- foreach ($order_taxes as $tax_id => $tax_item) {
- $column_label = !empty($tax_item['label']) ? $tax_item['label'] : __('Tax', 'wc-frontend-manager');
- $tax_breakups[$tax_item->get_rate_id()] = array('label' => $column_label, 'subtotal' => 0, 'total' => 0);
- }
- }
- $line_items_shipping = $order->get_items('shipping');
- $line_items_shipping = apply_filters('wcfm_valid_shipping_items', $line_items_shipping, $order_id);
- if (!empty($tax_breakups)) {
- foreach ($line_items_shipping as $shipping_item_id => $shipping_item) {
- if ($tax_data = $shipping_item->get_taxes()) {
- foreach ($order_taxes as $tax_item) {
- $tax_item_id = $tax_item->get_rate_id();
- $tax_item_total = isset($tax_data['total'][$tax_item_id]) ? $tax_data['total'][$tax_item_id] : 0;
- if (isset($tax_breakups[$tax_item_id])) {
- $tax_breakups[$tax_item_id]['total'] += (float)$tax_item_total;
- }
- }
- }
- }
- do_action('wcfm_vendor_order_details_before_shipping_tax_breakup', $order_id, $WCFM->wcfm_marketplace->vendor_id);
- foreach ($tax_breakups as $tax_breakup_is => $tax_breakup) {
- ?>
- <tr>
- <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php echo esc_html__('Shipping Tax', 'wc-frontend-manager') . ' ' . $tax_breakup['label']; ?>:</th>
- <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
- <div class="view">
- <?php
- echo wc_price($tax_breakup['total'], array('currency' => $order_currency));
- ?>
- </div>
- </td>
- </tr>
- <?php
- }
- do_action('wcfm_vendor_order_details_after_shipping_tax_breakup', $order_id, $WCFM->wcfm_marketplace->vendor_id);
- }
- }
- ?>
- <?php if (apply_filters('wcfm_is_allow_vendor_order_details_tax_breakup_total', true)) { ?>
- <?php do_action('wcfm_vendor_order_details_before_shipping_tax', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <tr>
- <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>">
- <?php if (apply_filters('wcfm_is_allow_vendor_order_details_tax_breakup', false)) {
- echo esc_html__('Total', 'wc-frontend-manager') . ' ';
- } ?>
- <?php esc_html_e('Shipping Tax', 'wc-frontend-manager'); ?>:
- </th>
- <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
- <div class="view">
- <?php
- if (apply_filters('wcfm_is_allow_vendor_order_details_commission_on_tax', false) && (round($shipping_tax, 2) != round($order_due[0]->shipping_tax_amount, 2))) {
- echo "<del>" . wc_price($shipping_tax, array('currency' => $order_currency)) . "</del>";
- echo "<ins>" . wc_price($order_due[0]->shipping_tax_amount, array('currency' => $order_currency)) . "</ins>";
- } else {
- echo wc_price($order_due[0]->shipping_tax_amount, array('currency' => $order_currency));
- }
- ?>
- </div>
- </td>
- </tr>
- <?php do_action('wcfm_vendor_order_details_after_shipping_tax', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <?php } ?>
- <?php } ?>
- <?php } ?>
- <?php if ($refund_total) { ?>
- <?php do_action('wcfm_vendor_order_details_before_refund', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <tr>
- <th class="label refunded-total" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php esc_html_e('Refunded', 'wc-frontend-manager'); ?>:</th>
- <td class="total refunded-total" style="text-align:center; <?php echo esc_attr($td_style); ?>">-<?php echo wc_price($refund_total, array('currency' => $order_currency)); ?></td>
- </tr>
- <?php do_action('wcfm_vendor_order_details_before_refund', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <?php } ?>
- <?php if ($discount_total && $WCFMmp->wcfmmp_vendor->is_vendor_deduct_discount($WCFM->wcfm_marketplace->vendor_id, $order_id)) { ?>
- <?php do_action('wcfm_vendor_order_details_before_discount', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <tr>
- <th class="label discount-total" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php esc_html_e('Discount', 'wc-frontend-manager'); ?>:</th>
- <td class="total discount-total" style="text-align:center; <?php echo esc_attr($td_style); ?>"><?php echo wc_price($discount_total, array('currency' => $order_currency)); ?></td>
- </tr>
- <?php do_action('wcfm_vendor_order_details_after_discount', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <?php } ?>
- <?php if (apply_filters('wcfm_is_allow_gross_total', true)) { ?>
- <?php do_action('wcfm_vendor_order_details_before_gross_total', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <tr class="total_cost">
- <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php esc_html_e('Gross Total', 'wc-frontend-manager'); ?>:</th>
- <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
- <div class="view">
- <?php
- if ($refund_total) {
- echo "<del>" . wc_price($calculated_total, array('currency' => $order_currency)) . "</del>";
- echo "<ins>" . wc_price($gross_sale_order, array('currency' => $order_currency)) . "</ins>";
- } else {
- echo wc_price($gross_sale_order, array('currency' => $order_currency));
- }
- ?>
- </div>
- </td>
- </tr>
- <?php do_action('wcfm_vendor_order_details_after_gross_total', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <?php } ?>
- <?php
- if (apply_filters('wcfm_is_allow_order_details_commission_breakup_gross_earning', true) && wcfm_vendor_has_capability($WCFM->wcfm_marketplace->vendor_id, 'view_commission') && !in_array($order_status, array('failed', 'cancelled', 'refunded', 'request', 'proposal', 'proposal-sent', 'proposal-expired', 'proposal-rejected', 'proposal-canceled', 'proposal-accepted'))) {
- if (!$admin_fee_mode || ($admin_fee_mode && apply_filters('wcfm_is_allow_admin_fee_mode_commission_breakup', true))) {
- if (isset($commission_rule['tax_enable']) && ($commission_rule['tax_enable'] == 'yes')) {
- ?>
- <?php do_action('wcfm_vendor_order_details_before_gross_earning', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <tr>
- <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php esc_html_e('Gross Earning', 'wc-frontend-manager'); ?>:</th>
- <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
- <div class="view">
- <?php
- echo wc_price(($total + $commission_tax + $aff_commission + $transaction_charge), array('currency' => $order_currency));
- ?>
- </div>
- </td>
- </tr>
- <?php do_action('wcfm_vendor_order_details_after_gross_earning', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <?php
- if ($aff_commission && apply_filters('wcfm_is_allow_view_affiliate_commission', true)) {
- ?>
- <?php do_action('wcfm_vendor_order_details_before_affiliate_commission', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <tr>
- <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php esc_html_e('Affiliate Commission', 'wc-frontend-manager'); ?>:</th>
- <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
- <div class="view">
- <?php
- echo '-' . wc_price($aff_commission, array('currency' => $order_currency));
- ?>
- </div>
- </td>
- </tr>
- <?php do_action('wcfm_vendor_order_details_after_affiliate_commission', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <?php
- }
- ?>
- <?php do_action('wcfm_vendor_order_details_before_commission_tax', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <tr>
- <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php echo esc_html($commission_rule['tax_name']) . ' (' . $commission_rule['tax_percent'] . '%)'; ?>:</th>
- <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
- <div class="view">
- <?php
- echo '-' . wc_price($commission_tax, array('currency' => $order_currency));
- ?>
- </div>
- </td>
- </tr>
- <?php do_action('wcfm_vendor_order_details_after_commission_tax', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <?php
- } elseif ($aff_commission && apply_filters('wcfm_is_allow_view_affiliate_commission', true)) {
- ?>
- <?php do_action('wcfm_vendor_order_details_before_gross_earning', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <tr>
- <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php esc_html_e('Gross Earning', 'wc-frontend-manager'); ?>:</th>
- <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
- <div class="view">
- <?php
- echo wc_price(($total + $aff_commission + $transaction_charge), array('currency' => $order_currency));
- ?>
- </div>
- </td>
- </tr>
- <?php do_action('wcfm_vendor_order_details_after_gross_earning', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <?php do_action('wcfm_vendor_order_details_before_affiliate_commission', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <tr>
- <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php esc_html_e('Affiliate Commission', 'wc-frontend-manager'); ?>:</th>
- <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
- <div class="view">
- <?php
- echo '-' . wc_price($aff_commission, array('currency' => $order_currency));
- ?>
- </div>
- </td>
- </tr>
- <?php do_action('wcfm_vendor_order_details_after_affiliate_commission', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <?php
- }
- ?>
- <?php
- // Show Transaction Charges
- if ($transaction_charge && apply_filters('wcfm_is_allow_view_transaction_charge', true) && isset($commission_rule['transaction_charge_type']) && ($commission_rule['transaction_charge_type'] != 'no')) {
- ?>
- <?php if (!$aff_commission && (!isset($commission_rule['tax_enable']) || (isset($commission_rule['tax_enable']) && ($commission_rule['tax_enable'] != 'yes')))) { ?>
- <?php do_action('wcfm_vendor_order_details_before_gross_earning', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <tr>
- <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php esc_html_e('Gross Earning', 'wc-frontend-manager'); ?>:</th>
- <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
- <div class="view">
- <?php
- echo wc_price(($total + $transaction_charge), array('currency' => $order_currency));
- ?>
- </div>
- </td>
- </tr>
- <?php do_action('wcfm_vendor_order_details_after_gross_earning', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <?php } ?>
- <?php do_action('wcfm_vendor_order_details_before_transaction_charge', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <tr>
- <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php esc_html_e('Transaction Charge', 'wc-frontend-manager'); ?>:</th>
- <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
- <div class="view">
- <?php
- echo '-' . wc_price($transaction_charge, array('currency' => $order_currency));
- ?>
- </div>
- </td>
- </tr>
- <?php do_action('wcfm_vendor_order_details_after_transaction_charge', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <?php
- }
- ?>
- <?php do_action('wcfm_vendor_order_details_before_total_earning', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <tr>
- <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php esc_html_e('Total Earning', 'wc-frontend-manager'); ?>:</th>
- <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
- <div class="view">
- <?php
- echo wc_price($total, array('currency' => $order_currency));
- if (apply_filters('wcfm_is_allow_earning_in_words', false)) {
- echo "<br/>" . wcfm_number_to_words($total);
- }
- ?>
- </div>
- </td>
- </tr>
- <?php do_action('wcfm_vendor_order_details_after_total_earning', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
- <?php
- }
- if (apply_filters('wcfm_is_allow_order_details_admin_fee', true)) {
- do_action('wcfm_vendor_order_details_before_admin_fee', $order_id, $WCFM->wcfm_marketplace->vendor_id);
- $order = wc_get_order( $order_id );
- $fees = $order->get_fees();
- $tax_display = '';
- $tax_display = $tax_display ? $tax_display : get_option( 'woocommerce_tax_display_cart' );
- $total_fee = 0;
- if ( $fees ) {
- foreach ( $fees as $id => $fee ) {
- if( 'excl' === $tax_display ) {
- $total_fee += $fee->get_total();
- } else {
- $total_fee += $fee->get_total() + $fee->get_total_tax();
- }
- }
- }
- ?>
- <tr>
- <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php esc_html_e('Comission', 'wc-frontend-manager'); ?>:</th>
- <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
- <div class="view">
- <?php
- echo wc_price(($gross_sale_order - $total), array('currency' => $order_currency));
- if (apply_filters('wcfm_is_allow_earning_in_words', false)) {
- echo "<br/>" . wcfm_number_to_words(($gross_sale_order - $total));
- }
- ?>
- </div>
- </td>
- </tr>
- <?php
- do_action('wcfm_vendor_order_details_after_admin_fee', $order_id, $WCFM->wcfm_marketplace->vendor_id);
- }
- }
- }
- add_action( 'wcfm_vendor_order_details_after_admin_fee', function( $order_id, $vendor_id ) {
- global $WCFM, $wpdb;
- $order = wc_get_order( $order_id );
- $fees = $order->get_fees();
- $tax_display = '';
- $tax_display = $tax_display ? $tax_display : get_option( 'woocommerce_tax_display_cart' );
- $total_fee = 0;
- if ( $fees ) {
- foreach ( $fees as $id => $fee ) {
- if( 'excl' === $tax_display ) {
- $total_fee += $fee->get_total();
- } else {
- $total_fee += $fee->get_total() + $fee->get_total_tax();
- }
- ?>
- <tr>
- <th class="label" colspan="2" style="text-align:right;"><?php echo $fee->get_name() . ':'; ?></th>
- <td class="total" style="text-align:center;">
- <div class="view">
- <?php echo wc_price( 'excl' === $tax_display ? $fee->get_total() : $fee->get_total() + $fee->get_total_tax(), array( 'currency' => $order->get_currency() ) ); ?>
- </div>
- </td>
- </tr>
- <?php
- }
- }
- $sql = "SELECT
- GROUP_CONCAT(ID) as commission_ids,
- GROUP_CONCAT(item_id) as order_item_ids,
- SUM(commission_amount) as line_total,
- SUM(total_commission) as total_commission,
- SUM(item_total) as item_total,
- SUM(item_sub_total) as item_sub_total,
- SUM(shipping) as shipping,
- SUM(tax) as tax,
- SUM(shipping_tax_amount) as shipping_tax_amount,
- SUM(refunded_amount) as refunded_amount,
- SUM(discount_amount) as discount_amount
- FROM
- {$wpdb->prefix}wcfm_marketplace_orders
- WHERE
- order_id = % d
- AND `vendor_id` = % d
- AND `is_refunded` != 1
- ";
- $order_due = $wpdb->get_results($wpdb->prepare($sql, $order_id, $vendor_id));
- if (!$order_due || !isset($order_due[0])) return;
- $total = $order_due[0]->total_commission;
- $gross_sale_order = $WCFM->wcfm_vendor_support->wcfm_get_gross_sales_by_vendor($vendor_id, '', '', $order_id);
- ?>
- <tr>
- <th class="label" colspan="2" style="text-align:right;"><?php esc_html_e('Admin Fee', 'wc-frontend-manager'); ?>:</th>
- <td class="total" style="text-align:center;">
- <div class="view">
- <?php
- echo wc_price(($gross_sale_order - $total) + $total_fee, array('currency' => $order->get_currency()));
- if (apply_filters('wcfm_is_allow_earning_in_words', false)) {
- echo "<br/>" . wcfm_number_to_words(($gross_sale_order - $total) + $total_fee);
- }
- ?>
- </div>
- </td>
- </tr>
- <?php
- }, 10, 2 );
Comments
-
- Adding Handling & service fees in vendor email and it shows the admin fee total = commission + handling & service fees
Add Comment
Please, Sign In to add comment