MichelH

Add Handling & Service Fees in WCFM Vendor email

Apr 5th, 2023 (edited)
37
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 32.88 KB | Source Code | 0 0
  1. add_action ( 'wcfm_order_totals_after_total', function() {
  2.     global $WCFM;
  3.     remove_action ( 'wcfm_order_totals_after_total', array( $WCFM->wcfm_marketplace, 'wcfmmp_order_total_commission' ) );
  4.     add_action ( 'wcfm_order_totals_after_total', 'wcfmmp_order_total_commission', 11 );
  5. }, 9 );
  6.  
  7. // WCFM Marketplace Order Total Commission
  8. function wcfmmp_order_total_commission($order_id)
  9. {
  10.     global $WCFM, $wpdb, $WCFMmp;
  11.  
  12.     $admin_fee_mode = apply_filters('wcfm_is_admin_fee_mode', false);
  13.     $gross_sale_order = $WCFM->wcfm_vendor_support->wcfm_get_gross_sales_by_vendor($WCFM->wcfm_marketplace->vendor_id, '', '', $order_id);
  14.     $order = wc_get_order($order_id);
  15.     $order_currency = $order->get_currency();
  16.  
  17.     $order_status = sanitize_title($order->get_status());
  18.  
  19.     $td_style = '';
  20.  
  21.     $sql = "SELECT
  22.                 GROUP_CONCAT(ID) as commission_ids,
  23.                 GROUP_CONCAT(item_id) as order_item_ids,
  24.                 SUM(commission_amount) as line_total,
  25.                 SUM(total_commission) as total_commission,
  26.                 SUM(item_total) as item_total,
  27.                 SUM(item_sub_total) as item_sub_total,
  28.                 SUM(shipping) as shipping,
  29.                 SUM(tax) as tax,
  30.                 SUM(shipping_tax_amount) as shipping_tax_amount,
  31.                 SUM(refunded_amount) as refunded_amount,
  32.                 SUM(discount_amount) as discount_amount
  33.             FROM
  34.                 {$wpdb->prefix}wcfm_marketplace_orders
  35.             WHERE
  36.                 order_id = % d
  37.                 AND `vendor_id` = % d
  38.                 AND `is_refunded` != 1
  39.             ";
  40.     $order_due = $wpdb->get_results($wpdb->prepare($sql, $order_id, $WCFM->wcfm_marketplace->vendor_id));
  41.     if (!$order_due || !isset($order_due[0])) return;
  42.  
  43.     $total = 0;
  44.     $subtotal = 0;
  45.     $calculated_total   = 0;
  46.     $total_tax          = 0;
  47.     $total_shipping     = 0;
  48.     $shipping_tax       = 0;
  49.     $refund_total       = 0;
  50.     $discount_total     = 0;
  51.     $commission_tax     = 0;
  52.     $aff_commission     = 0;
  53.     $transaction_charge = 0;
  54.  
  55.     $commission_rule  = array();
  56.     $aff_commission_rule = array();
  57.  
  58.     $total = $order_due[0]->total_commission;
  59.     if ($WCFMmp->wcfmmp_vendor->is_vendor_deduct_discount($WCFM->wcfm_marketplace->vendor_id, $order_id)) {
  60.         $calculated_total = $order_due[0]->item_total;
  61.     } else {
  62.         $calculated_total = $order_due[0]->item_sub_total;
  63.     }
  64.     //$calculated_total += ( float ) $order_due[0]->tax;
  65.  
  66.     // WC Refund Support - 3.0.4
  67.     $commission_ids = explode(",", $order_due[0]->commission_ids);
  68.     foreach ($commission_ids as $commission_id) {
  69.         if (method_exists($WCFMmp->wcfmmp_commission, 'wcfmmp_get_commission_meta')) {
  70.             $total_tax          += (float) $WCFMmp->wcfmmp_commission->wcfmmp_get_commission_meta($commission_id, 'gross_tax_cost');
  71.             $total_shipping     += (float) $WCFMmp->wcfmmp_commission->wcfmmp_get_commission_meta($commission_id, 'gross_shipping_cost');
  72.             $shipping_tax       += (float) $WCFMmp->wcfmmp_commission->wcfmmp_get_commission_meta($commission_id, 'gross_shipping_tax');
  73.             $commission_tax     += (float) $WCFMmp->wcfmmp_commission->wcfmmp_get_commission_meta($commission_id, 'commission_tax');
  74.             $aff_commission     += (float) $WCFMmp->wcfmmp_commission->wcfmmp_get_commission_meta($commission_id, '_wcfm_affiliate_commission');
  75.             $transaction_charge += (float) $WCFMmp->wcfmmp_commission->wcfmmp_get_commission_meta($commission_id, 'transaction_charge');
  76.             $commission_rule     = unserialize($WCFMmp->wcfmmp_commission->wcfmmp_get_commission_meta($commission_id, 'commission_rule'));
  77.             //$aff_commission_rule = unserialize( $WCFMmp->wcfmmp_commission->wcfmmp_get_commission_meta( $commission_id, '_wcfm_affiliate_commission_rule' ) );
  78.         }
  79.     }
  80.  
  81.     //print_r($commission_rule );
  82.     //print_r($aff_commission_rule);
  83.  
  84.  
  85.     $calculated_total += (float) $total_tax;
  86.     $calculated_total += (float) apply_filters('wcfmmmp_gross_sales_shipping_cost', $total_shipping, $WCFM->wcfm_marketplace->vendor_id);
  87.     $calculated_total += (float) $shipping_tax;
  88.  
  89.     $refund_total = $order_due[0]->refunded_amount;
  90.     $discount_total = $order_due[0]->discount_amount;
  91.     if ($get_shipping = $WCFMmp->wcfmmp_vendor->is_vendor_get_shipping($WCFM->wcfm_marketplace->vendor_id)) {
  92.         //$total += ( float ) $order_due[0]->shipping;
  93.     }
  94.     if ($get_tax = $WCFMmp->wcfmmp_vendor->is_vendor_get_tax($WCFM->wcfm_marketplace->vendor_id)) {
  95.         //$total += (float) $order_due[0]->tax;
  96.         if ($get_shipping) {
  97.             //$total += ( float ) $order_due[0]->shipping_tax_amount;
  98.         }
  99.     }
  100.     ?>
  101.     <?php //if( !$admin_fee_mode ) {
  102.     ?>
  103.     <?php do_action('wcfm_vendor_order_details_before_subtotal', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  104.     <tr>
  105.         <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php esc_html_e('Subtotal', 'wc-frontend-manager'); ?>:</th>
  106.         <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
  107.             <div class="view">
  108.                 <?php
  109.                 $subtotal = $calculated_total - ((float) $refund_total + (float) $order_due[0]->shipping + (float) $order_due[0]->tax + (float) $order_due[0]->shipping_tax_amount);
  110.                 if ($refund_total && (round($subtotal, 2) != round($order_due[0]->item_sub_total, 2))) {
  111.                     echo "<del>" . wc_price($order_due[0]->item_sub_total, array('currency' => $order_currency)) . "</del>";
  112.                     echo "<ins>" . wc_price($subtotal, array('currency' => $order_currency)) . "</ins>";
  113.                 } else {
  114.                     echo wc_price($order_due[0]->item_sub_total, array('currency' => $order_currency));
  115.                 }
  116.                 ?>
  117.             </div>
  118.         </td>
  119.     </tr>
  120.     <?php do_action('wcfm_vendor_order_details_after_subtotal', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  121.     <?php //}
  122.     ?>
  123.     <?php if ($get_tax) { ?>
  124.         <?php
  125.         if (apply_filters('wcfm_is_allow_vendor_order_details_tax_breakup', false)) {
  126.             $order_taxes = $order->get_taxes();
  127.             $tax_breakups = array();
  128.             if (!empty($order_taxes)) {
  129.                 foreach ($order_taxes as $tax_id => $tax_item) {
  130.                     $column_label   = !empty($tax_item['label']) ? $tax_item['label'] : __('Tax', 'wc-frontend-manager');
  131.                     $tax_breakups[$tax_item->get_rate_id()] = array('label' => $column_label, 'subtotal' => 0, 'total' => 0);
  132.                 }
  133.             }
  134.  
  135.             if (!empty($tax_breakups)) {
  136.                 $order_item_ids = explode(",", $order_due[0]->order_item_ids);
  137.                 foreach ($order_item_ids as $order_item_id) {
  138.                     $line_item       = new WC_Order_Item_Product($order_item_id);
  139.                     if ($tax_data = $line_item->get_taxes()) {
  140.                         foreach ($order_taxes as $tax_item) {
  141.                             $tax_item_id    = $tax_item->get_rate_id();
  142.                             $tax_item_total = isset($tax_data['total'][$tax_item_id]) ? $tax_data['total'][$tax_item_id] : 0;
  143.                             $tax_item_subtotal = isset($tax_data['subtotal'][$tax_item_id]) ? $tax_data['subtotal'][$tax_item_id] : 0;
  144.  
  145.                             if (isset($tax_breakups[$tax_item_id])) {
  146.                                 $tax_breakups[$tax_item_id]['subtotal'] += (float)$tax_item_subtotal;
  147.                                 $tax_breakups[$tax_item_id]['total'] += (float)$tax_item_total;
  148.                             }
  149.                         }
  150.                     }
  151.                 }
  152.  
  153.                 do_action('wcfm_vendor_order_details_before_tax_breakup', $order_id, $WCFM->wcfm_marketplace->vendor_id);
  154.  
  155.                 foreach ($tax_breakups as $tax_breakup_is => $tax_breakup) {
  156.                     ?>
  157.                     <tr>
  158.                         <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php echo esc_html($tax_breakup['label']); ?>:</th>
  159.                         <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
  160.                             <div class="view">
  161.                                 <?php
  162.                                 if (apply_filters('wcfm_is_allow_vendor_order_details_commission_on_tax', false) && (round($tax_breakup['total'], 2) != round($tax_breakup['subtotal'], 2))) {
  163.                                     echo "<del>" . wc_price($tax_breakup['total'], array('currency' => $order_currency)) . "</del>";
  164.                                     echo "<ins>" . wc_price($tax_breakup['subtotal'], array('currency' => $order_currency)) . "</ins>";
  165.                                 } else {
  166.                                     echo wc_price($tax_breakup['subtotal'], array('currency' => $order_currency));
  167.                                 }
  168.                                 ?>
  169.                             </div>
  170.                         </td>
  171.                     </tr>
  172.                     <?php
  173.                 }
  174.  
  175.                 do_action('wcfm_vendor_order_details_after_tax_breakup', $order_id, $WCFM->wcfm_marketplace->vendor_id);
  176.             }
  177.         }
  178.         ?>
  179.         <?php if (apply_filters('wcfm_is_allow_vendor_order_details_tax_breakup_total', true)) { ?>
  180.  
  181.             <?php do_action('wcfm_vendor_order_details_before_tax', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  182.             <tr>
  183.                 <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>">
  184.                     <?php if (apply_filters('wcfm_is_allow_vendor_order_details_tax_breakup', false)) {
  185.                         echo esc_html__('Total', 'wc-frontend-manager') . ' ';
  186.                     } ?>
  187.                     <?php esc_html_e('Tax', 'wc-frontend-manager'); ?>:
  188.                 </th>
  189.                 <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
  190.                     <div class="view">
  191.                         <?php
  192.                         if (apply_filters('wcfm_is_allow_vendor_order_details_commission_on_tax', false) && (round($total_tax, 2) != round($order_due[0]->tax, 2))) {
  193.                             echo "<del>" . wc_price($total_tax, array('currency' => $order_currency)) . "</del>";
  194.                             echo "<ins>" . wc_price($order_due[0]->tax, array('currency' => $order_currency)) . "</ins>";
  195.                         } else {
  196.                             echo wc_price($order_due[0]->tax, array('currency' => $order_currency));
  197.                         }
  198.                         ?>
  199.                     </div>
  200.                 </td>
  201.             </tr>
  202.             <?php do_action('wcfm_vendor_order_details_after_tax', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  203.  
  204.         <?php } ?>
  205.     <?php } ?>
  206.     <?php if ($get_shipping && $order->get_formatted_shipping_address()) { ?>
  207.  
  208.         <?php do_action('wcfm_vendor_order_details_before_shipping', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  209.         <tr>
  210.             <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php esc_html_e('Shipping', 'wc-frontend-manager'); ?>:</th>
  211.             <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
  212.                 <div class="view">
  213.                     <?php
  214.                     if (apply_filters('wcfm_is_allow_vendor_order_details_commission_on_shipping', false) && (round($total_shipping, 2) != round($order_due[0]->shipping, 2))) {
  215.                         echo "<del>" . wc_price($total_shipping, array('currency' => $order_currency)) . "</del>";
  216.                         echo "<ins>" . wc_price($order_due[0]->shipping, array('currency' => $order_currency)) . "</ins>";
  217.                     } else {
  218.                         echo wc_price(apply_filters('wcfmmmp_gross_sales_shipping_cost', $order_due[0]->shipping, $WCFM->wcfm_marketplace->vendor_id), array('currency' => $order_currency));
  219.                     }
  220.                     ?>
  221.                 </div>
  222.             </td>
  223.         </tr>
  224.         <?php do_action('wcfm_vendor_order_details_after_shipping', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  225.  
  226.         <?php if ($get_tax) { ?>
  227.             <?php
  228.             if (apply_filters('wcfm_is_allow_vendor_order_details_tax_breakup', false)) {
  229.                 $order_taxes = $order->get_taxes();
  230.                 $tax_breakups = array();
  231.                 if (!empty($order_taxes)) {
  232.                     foreach ($order_taxes as $tax_id => $tax_item) {
  233.                         $column_label   = !empty($tax_item['label']) ? $tax_item['label'] : __('Tax', 'wc-frontend-manager');
  234.                         $tax_breakups[$tax_item->get_rate_id()] = array('label' => $column_label, 'subtotal' => 0, 'total' => 0);
  235.                     }
  236.                 }
  237.  
  238.                 $line_items_shipping = $order->get_items('shipping');
  239.                 $line_items_shipping = apply_filters('wcfm_valid_shipping_items', $line_items_shipping, $order_id);
  240.  
  241.                 if (!empty($tax_breakups)) {
  242.                     foreach ($line_items_shipping as $shipping_item_id => $shipping_item) {
  243.                         if ($tax_data = $shipping_item->get_taxes()) {
  244.                             foreach ($order_taxes as $tax_item) {
  245.                                 $tax_item_id    = $tax_item->get_rate_id();
  246.                                 $tax_item_total = isset($tax_data['total'][$tax_item_id]) ? $tax_data['total'][$tax_item_id] : 0;
  247.  
  248.                                 if (isset($tax_breakups[$tax_item_id])) {
  249.                                     $tax_breakups[$tax_item_id]['total'] += (float)$tax_item_total;
  250.                                 }
  251.                             }
  252.                         }
  253.                     }
  254.  
  255.                     do_action('wcfm_vendor_order_details_before_shipping_tax_breakup', $order_id, $WCFM->wcfm_marketplace->vendor_id);
  256.  
  257.                     foreach ($tax_breakups as $tax_breakup_is => $tax_breakup) {
  258.                         ?>
  259.                         <tr>
  260.                             <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>
  261.                             <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
  262.                                 <div class="view">
  263.                                     <?php
  264.                                     echo wc_price($tax_breakup['total'], array('currency' => $order_currency));
  265.                                     ?>
  266.                                 </div>
  267.                             </td>
  268.                         </tr>
  269.                         <?php
  270.                     }
  271.  
  272.                     do_action('wcfm_vendor_order_details_after_shipping_tax_breakup', $order_id, $WCFM->wcfm_marketplace->vendor_id);
  273.                 }
  274.             }
  275.             ?>
  276.             <?php if (apply_filters('wcfm_is_allow_vendor_order_details_tax_breakup_total', true)) { ?>
  277.                 <?php do_action('wcfm_vendor_order_details_before_shipping_tax', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  278.                 <tr>
  279.                     <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>">
  280.                         <?php if (apply_filters('wcfm_is_allow_vendor_order_details_tax_breakup', false)) {
  281.                             echo esc_html__('Total', 'wc-frontend-manager') . ' ';
  282.                         } ?>
  283.                         <?php esc_html_e('Shipping Tax', 'wc-frontend-manager'); ?>:
  284.                     </th>
  285.                     <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
  286.                         <div class="view">
  287.                             <?php
  288.                             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))) {
  289.                                 echo "<del>" . wc_price($shipping_tax, array('currency' => $order_currency)) . "</del>";
  290.                                 echo "<ins>" . wc_price($order_due[0]->shipping_tax_amount, array('currency' => $order_currency)) . "</ins>";
  291.                             } else {
  292.                                 echo wc_price($order_due[0]->shipping_tax_amount, array('currency' => $order_currency));
  293.                             }
  294.                             ?>
  295.                         </div>
  296.                     </td>
  297.                 </tr>
  298.                 <?php do_action('wcfm_vendor_order_details_after_shipping_tax', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  299.             <?php } ?>
  300.         <?php } ?>
  301.     <?php } ?>
  302.  
  303.     <?php if ($refund_total) { ?>
  304.         <?php do_action('wcfm_vendor_order_details_before_refund', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  305.         <tr>
  306.             <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>
  307.             <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>
  308.         </tr>
  309.         <?php do_action('wcfm_vendor_order_details_before_refund', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  310.     <?php } ?>
  311.  
  312.     <?php if ($discount_total && $WCFMmp->wcfmmp_vendor->is_vendor_deduct_discount($WCFM->wcfm_marketplace->vendor_id, $order_id)) { ?>
  313.         <?php do_action('wcfm_vendor_order_details_before_discount', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  314.         <tr>
  315.             <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>
  316.             <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>
  317.         </tr>
  318.         <?php do_action('wcfm_vendor_order_details_after_discount', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  319.     <?php } ?>
  320.  
  321.     <?php if (apply_filters('wcfm_is_allow_gross_total', true)) { ?>
  322.         <?php do_action('wcfm_vendor_order_details_before_gross_total', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  323.         <tr class="total_cost">
  324.             <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>
  325.             <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
  326.                 <div class="view">
  327.                     <?php
  328.                     if ($refund_total) {
  329.                         echo "<del>" . wc_price($calculated_total, array('currency' => $order_currency)) . "</del>";
  330.                         echo "<ins>" . wc_price($gross_sale_order, array('currency' => $order_currency)) . "</ins>";
  331.                     } else {
  332.                         echo wc_price($gross_sale_order, array('currency' => $order_currency));
  333.                     }
  334.                     ?>
  335.                 </div>
  336.             </td>
  337.         </tr>
  338.         <?php do_action('wcfm_vendor_order_details_after_gross_total', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  339.     <?php } ?>
  340.  
  341.     <?php
  342.     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'))) {
  343.         if (!$admin_fee_mode || ($admin_fee_mode && apply_filters('wcfm_is_allow_admin_fee_mode_commission_breakup', true))) {
  344.             if (isset($commission_rule['tax_enable']) && ($commission_rule['tax_enable'] == 'yes')) {
  345.             ?>
  346.  
  347.                 <?php do_action('wcfm_vendor_order_details_before_gross_earning', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  348.                 <tr>
  349.                     <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>
  350.                     <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
  351.                         <div class="view">
  352.                             <?php
  353.                             echo wc_price(($total + $commission_tax + $aff_commission + $transaction_charge), array('currency' => $order_currency));
  354.                             ?>
  355.                         </div>
  356.                     </td>
  357.                 </tr>
  358.                 <?php do_action('wcfm_vendor_order_details_after_gross_earning', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  359.  
  360.                 <?php
  361.                 if ($aff_commission && apply_filters('wcfm_is_allow_view_affiliate_commission', true)) {
  362.                 ?>
  363.                     <?php do_action('wcfm_vendor_order_details_before_affiliate_commission', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  364.                     <tr>
  365.                         <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>
  366.                         <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
  367.                             <div class="view">
  368.                                 <?php
  369.                                 echo '-' . wc_price($aff_commission, array('currency' => $order_currency));
  370.                                 ?>
  371.                             </div>
  372.                         </td>
  373.                     </tr>
  374.                     <?php do_action('wcfm_vendor_order_details_after_affiliate_commission', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  375.                 <?php
  376.                 }
  377.                 ?>
  378.  
  379.                 <?php do_action('wcfm_vendor_order_details_before_commission_tax', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  380.                 <tr>
  381.                     <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>
  382.                     <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
  383.                         <div class="view">
  384.                             <?php
  385.                             echo '-' . wc_price($commission_tax, array('currency' => $order_currency));
  386.                             ?>
  387.                         </div>
  388.                     </td>
  389.                 </tr>
  390.                 <?php do_action('wcfm_vendor_order_details_after_commission_tax', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  391.  
  392.             <?php
  393.             } elseif ($aff_commission && apply_filters('wcfm_is_allow_view_affiliate_commission', true)) {
  394.             ?>
  395.  
  396.                 <?php do_action('wcfm_vendor_order_details_before_gross_earning', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  397.                 <tr>
  398.                     <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>
  399.                     <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
  400.                         <div class="view">
  401.                             <?php
  402.                             echo wc_price(($total + $aff_commission + $transaction_charge), array('currency' => $order_currency));
  403.                             ?>
  404.                         </div>
  405.                     </td>
  406.                 </tr>
  407.                 <?php do_action('wcfm_vendor_order_details_after_gross_earning', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  408.  
  409.                 <?php do_action('wcfm_vendor_order_details_before_affiliate_commission', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  410.                 <tr>
  411.                     <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>
  412.                     <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
  413.                         <div class="view">
  414.                             <?php
  415.                             echo '-' . wc_price($aff_commission, array('currency' => $order_currency));
  416.                             ?>
  417.                         </div>
  418.                     </td>
  419.                 </tr>
  420.                 <?php do_action('wcfm_vendor_order_details_after_affiliate_commission', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  421.  
  422.             <?php
  423.             }
  424.             ?>
  425.  
  426.             <?php
  427.             // Show Transaction Charges
  428.             if ($transaction_charge && apply_filters('wcfm_is_allow_view_transaction_charge', true) && isset($commission_rule['transaction_charge_type']) && ($commission_rule['transaction_charge_type'] != 'no')) {
  429.             ?>
  430.  
  431.                 <?php if (!$aff_commission && (!isset($commission_rule['tax_enable']) || (isset($commission_rule['tax_enable']) && ($commission_rule['tax_enable'] != 'yes')))) { ?>
  432.  
  433.                     <?php do_action('wcfm_vendor_order_details_before_gross_earning', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  434.                     <tr>
  435.                         <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>
  436.                         <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
  437.                             <div class="view">
  438.                                 <?php
  439.                                 echo wc_price(($total + $transaction_charge), array('currency' => $order_currency));
  440.                                 ?>
  441.                             </div>
  442.                         </td>
  443.                     </tr>
  444.                     <?php do_action('wcfm_vendor_order_details_after_gross_earning', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  445.  
  446.                 <?php } ?>
  447.  
  448.                 <?php do_action('wcfm_vendor_order_details_before_transaction_charge', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  449.                 <tr>
  450.                     <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>
  451.                     <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
  452.                         <div class="view">
  453.                             <?php
  454.                             echo '-' . wc_price($transaction_charge, array('currency' => $order_currency));
  455.                             ?>
  456.                         </div>
  457.                     </td>
  458.                 </tr>
  459.                 <?php do_action('wcfm_vendor_order_details_after_transaction_charge', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  460.  
  461.             <?php
  462.             }
  463.             ?>
  464.  
  465.             <?php do_action('wcfm_vendor_order_details_before_total_earning', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  466.             <tr>
  467.                 <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>
  468.                 <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
  469.                     <div class="view">
  470.                         <?php
  471.                         echo wc_price($total, array('currency' => $order_currency));
  472.                         if (apply_filters('wcfm_is_allow_earning_in_words', false)) {
  473.                             echo "<br/>" . wcfm_number_to_words($total);
  474.                         }
  475.                         ?>
  476.                     </div>
  477.                 </td>
  478.             </tr>
  479.             <?php do_action('wcfm_vendor_order_details_after_total_earning', $order_id, $WCFM->wcfm_marketplace->vendor_id); ?>
  480.  
  481.         <?php
  482.         }
  483.         if (apply_filters('wcfm_is_allow_order_details_admin_fee', true)) {
  484.             do_action('wcfm_vendor_order_details_before_admin_fee', $order_id, $WCFM->wcfm_marketplace->vendor_id);
  485.             $order = wc_get_order( $order_id );
  486.             $fees = $order->get_fees();
  487.             $tax_display = '';
  488.             $tax_display = $tax_display ? $tax_display : get_option( 'woocommerce_tax_display_cart' );
  489.             $total_fee = 0;
  490.  
  491.             if ( $fees ) {
  492.                 foreach ( $fees as $id => $fee ) {
  493.                     if( 'excl' === $tax_display ) {
  494.                         $total_fee += $fee->get_total();
  495.                     } else {
  496.                         $total_fee += $fee->get_total() + $fee->get_total_tax();
  497.                     }
  498.                 }
  499.             }
  500.             ?>
  501.             <tr>
  502.                 <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php esc_html_e('Comission', 'wc-frontend-manager'); ?>:</th>
  503.                 <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
  504.                     <div class="view">
  505.                         <?php
  506.                         echo wc_price(($gross_sale_order - $total), array('currency' => $order_currency));
  507.                         if (apply_filters('wcfm_is_allow_earning_in_words', false)) {
  508.                             echo "<br/>" . wcfm_number_to_words(($gross_sale_order - $total));
  509.                         }
  510.                         ?>
  511.                     </div>
  512.                 </td>
  513.             </tr>
  514.             <?php
  515.             do_action('wcfm_vendor_order_details_after_admin_fee', $order_id, $WCFM->wcfm_marketplace->vendor_id);
  516.         }
  517.     }
  518. }
  519.  
  520. add_action( 'wcfm_vendor_order_details_after_admin_fee', function( $order_id, $vendor_id ) {
  521.     global $WCFM, $wpdb;
  522.  
  523.     $order = wc_get_order( $order_id );
  524.     $fees = $order->get_fees();
  525.     $tax_display = '';
  526.     $tax_display = $tax_display ? $tax_display : get_option( 'woocommerce_tax_display_cart' );
  527.     $total_fee = 0;
  528.  
  529.     if ( $fees ) {
  530.         foreach ( $fees as $id => $fee ) {
  531.             if( 'excl' === $tax_display ) {
  532.                 $total_fee += $fee->get_total();
  533.             } else {
  534.                 $total_fee += $fee->get_total() + $fee->get_total_tax();
  535.             }
  536.  
  537.             ?>
  538.             <tr>
  539.                 <th class="label" colspan="2" style="text-align:right;"><?php echo $fee->get_name() . ':'; ?></th>
  540.                 <td class="total" style="text-align:center;">
  541.                     <div class="view">
  542.                         <?php echo wc_price( 'excl' === $tax_display ? $fee->get_total() : $fee->get_total() + $fee->get_total_tax(), array( 'currency' => $order->get_currency() ) ); ?>
  543.                     </div>
  544.                 </td>
  545.             </tr>
  546.             <?php
  547.         }
  548.     }
  549.  
  550.     $sql = "SELECT
  551.                GROUP_CONCAT(ID) as commission_ids,
  552.                GROUP_CONCAT(item_id) as order_item_ids,
  553.                SUM(commission_amount) as line_total,
  554.                SUM(total_commission) as total_commission,
  555.                SUM(item_total) as item_total,
  556.                SUM(item_sub_total) as item_sub_total,
  557.                SUM(shipping) as shipping,
  558.                SUM(tax) as tax,
  559.                SUM(shipping_tax_amount) as shipping_tax_amount,
  560.                SUM(refunded_amount) as refunded_amount,
  561.                SUM(discount_amount) as discount_amount
  562.            FROM
  563.                {$wpdb->prefix}wcfm_marketplace_orders
  564.            WHERE
  565.                order_id = % d
  566.                AND `vendor_id` = % d
  567.                AND `is_refunded` != 1
  568.            ";
  569.  
  570.     $order_due = $wpdb->get_results($wpdb->prepare($sql, $order_id, $vendor_id));
  571.     if (!$order_due || !isset($order_due[0])) return;
  572.  
  573.     $total = $order_due[0]->total_commission;
  574.  
  575.     $gross_sale_order = $WCFM->wcfm_vendor_support->wcfm_get_gross_sales_by_vendor($vendor_id, '', '', $order_id);
  576.     ?>
  577.     <tr>
  578.         <th class="label" colspan="2" style="text-align:right;"><?php esc_html_e('Admin Fee', 'wc-frontend-manager'); ?>:</th>
  579.         <td class="total" style="text-align:center;">
  580.             <div class="view">
  581.                 <?php
  582.                 echo wc_price(($gross_sale_order - $total) + $total_fee, array('currency' => $order->get_currency()));
  583.                 if (apply_filters('wcfm_is_allow_earning_in_words', false)) {
  584.                     echo "<br/>" . wcfm_number_to_words(($gross_sale_order - $total) + $total_fee);
  585.                 }
  586.                 ?>
  587.             </div>
  588.         </td>
  589.     </tr>
  590.     <?php
  591. }, 10, 2 );
Comments
  • MichelH
    3 years
    # text 0.12 KB | 0 0
    1. 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