Advertisement
wclovers

Untitled

Mar 10th, 2023
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.85 KB | None | 0 0
  1. add_action( 'wcfm_vendor_order_details_after_admin_fee', function( $order_id, $vendor_id ) {
  2.     global $WCFMmp, $wpdb;
  3.  
  4.     $get_shipping = $WCFMmp->wcfmmp_vendor->is_vendor_get_shipping( $vendor_id );
  5.     $get_tax = $WCFMmp->wcfmmp_vendor->is_vendor_get_tax( $vendor_id );
  6.     $order = wc_get_order( $order_id );
  7.     $order_currency = $order->get_currency();
  8.    
  9.     $td_style = '';
  10.  
  11.     $total_tax          = 0;
  12.     $total_shipping     = 0;
  13.     $shipping_tax       = 0;
  14.     $commission_tax     = 0;
  15.     $aff_commission     = 0;
  16.     $transaction_charge = 0;
  17.    
  18.     $sql = "
  19.     SELECT GROUP_CONCAT(ID) as commission_ids,
  20.        GROUP_CONCAT(item_id) as order_item_ids,
  21.        SUM(commission_amount) as line_total,
  22.        SUM(total_commission) as total_commission,
  23.        SUM(item_total) as item_total,
  24.        SUM(item_sub_total) as item_sub_total,
  25.          SUM(shipping) as shipping,
  26.        SUM(tax) as tax,
  27.        SUM( shipping_tax_amount) as shipping_tax_amount,
  28.        SUM( refunded_amount) as refunded_amount,
  29.        SUM( discount_amount) as discount_amount
  30.        FROM {$wpdb->prefix}wcfm_marketplace_orders
  31.        WHERE order_id = %d
  32.        AND `vendor_id` = %d
  33.        AND `is_refunded` != 1";
  34.     $order_due = $wpdb->get_results( $wpdb->prepare( $sql, $order_id, $vendor_id ) );
  35.     if( !$order_due || !isset( $order_due[0] ) ) return;
  36.    
  37.     // WC Refund Support - 3.0.4
  38.     $commission_ids = explode( ",", $order_due[0]->commission_ids );
  39.     foreach( $commission_ids as $commission_id ) {
  40.         if( method_exists( $WCFMmp->wcfmmp_commission, 'wcfmmp_get_commission_meta' ) ) {
  41.             $total_shipping     += (float) $WCFMmp->wcfmmp_commission->wcfmmp_get_commission_meta( $commission_id, 'gross_shipping_cost' );
  42.             $shipping_tax       += (float) $WCFMmp->wcfmmp_commission->wcfmmp_get_commission_meta( $commission_id, 'gross_shipping_tax' );
  43.         }
  44.     }
  45.  
  46.     if ( !$get_shipping && $order->get_formatted_shipping_address() ) { ?>
  47.            
  48.         <?php do_action( 'wcfm_vendor_order_details_before_shipping', $order_id, $vendor_id ); ?>
  49.         <tr>
  50.             <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>"><?php esc_html_e( 'Shipping', 'wc-frontend-manager' ); ?>:</th>
  51.             <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
  52.                 <div class="view">
  53.                   <?php
  54.                     if( apply_filters( 'wcfm_is_allow_vendor_order_details_commission_on_shipping', false ) && ( round( $total_shipping, 2 ) != round( $order_due[0]->shipping, 2 ) ) ) {
  55.                         echo "<del>" . wc_price( $total_shipping, array( 'currency' => $order_currency ) ) . "</del>";
  56.                         echo "<ins>" . wc_price( $order_due[0]->shipping, array( 'currency' => $order_currency ) ) . "</ins>";
  57.                     } else {
  58.                         echo wc_price( apply_filters( 'wcfmmmp_gross_sales_shipping_cost', $order_due[0]->shipping, $vendor_id ), array( 'currency' => $order_currency ) );
  59.                     }
  60.                     ?>
  61.                 </div>
  62.             </td>
  63.         </tr>
  64.         <?php do_action( 'wcfm_vendor_order_details_after_shipping', $order_id, $vendor_id ); ?>
  65.        
  66.         <?php if( $get_tax ) { ?>
  67.             <?php
  68.             if( apply_filters( 'wcfm_is_allow_vendor_order_details_tax_breakup', false ) ) {
  69.                 $order_taxes = $order->get_taxes();
  70.                 $tax_breakups = array();
  71.                 if ( ! empty( $order_taxes ) ) {
  72.                     foreach ( $order_taxes as $tax_id => $tax_item ) {
  73.                         $column_label   = ! empty( $tax_item['label'] ) ? $tax_item['label'] : __( 'Tax', 'wc-frontend-manager' );
  74.                         $tax_breakups[$tax_item->get_rate_id()] = array( 'label' => $column_label, 'subtotal' => 0, 'total' => 0 );
  75.                     }
  76.                 }
  77.                
  78.                 $line_items_shipping = $order->get_items( 'shipping' );
  79.                 $line_items_shipping = apply_filters( 'wcfm_valid_shipping_items', $line_items_shipping, $order_id );
  80.                
  81.                 if( !empty( $tax_breakups ) ) {
  82.                     foreach ( $line_items_shipping as $shipping_item_id => $shipping_item ) {
  83.                         if ( $tax_data = $shipping_item->get_taxes() ) {
  84.                             foreach ( $order_taxes as $tax_item ) {
  85.                                 $tax_item_id    = $tax_item->get_rate_id();
  86.                                 $tax_item_total = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : 0;
  87.                                
  88.                                 if( isset( $tax_breakups[$tax_item_id] ) ) {
  89.                                     $tax_breakups[$tax_item_id]['total'] += (float)$tax_item_total;
  90.                                 }
  91.                             }
  92.                         }
  93.                     }
  94.                    
  95.                     do_action( 'wcfm_vendor_order_details_before_shipping_tax_breakup', $order_id, $vendor_id );
  96.                    
  97.                     foreach( $tax_breakups as $tax_breakup_is => $tax_breakup ) {
  98.                         ?>
  99.                         <tr>
  100.                             <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>
  101.                             <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
  102.                                 <div class="view">
  103.                                     <?php
  104.                                     echo wc_price( $tax_breakup['total'], array( 'currency' => $order_currency ) );
  105.                                     ?>
  106.                                 </div>
  107.                             </td>
  108.                         </tr>
  109.                         <?php
  110.                     }
  111.                    
  112.                     do_action( 'wcfm_vendor_order_details_after_shipping_tax_breakup', $order_id, $vendor_id );
  113.                 }
  114.             }
  115.             ?>
  116.             <?php if( apply_filters( 'wcfm_is_allow_vendor_order_details_tax_breakup_total', true ) ) { ?>
  117.                 <?php do_action( 'wcfm_vendor_order_details_before_shipping_tax', $order_id, $vendor_id ); ?>
  118.                 <tr>
  119.                     <th class="label" colspan="2" style="text-align:right; <?php echo esc_attr($td_style); ?>">
  120.                         <?php if( apply_filters( 'wcfm_is_allow_vendor_order_details_tax_breakup', false ) ) { echo esc_html__( 'Total', 'wc-frontend-manager' ) . ' '; } ?>
  121.                         <?php esc_html_e( 'Shipping Tax', 'wc-frontend-manager' ); ?>:
  122.                     </th>
  123.                     <td class="total" style="text-align:center; <?php echo esc_attr($td_style); ?>">
  124.                         <div class="view">
  125.                             <?php
  126.                             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 ) ) ) {
  127.                                 echo "<del>" . wc_price( $shipping_tax, array( 'currency' => $order_currency ) ) . "</del>";
  128.                                 echo "<ins>" . wc_price( $order_due[0]->shipping_tax_amount, array( 'currency' => $order_currency ) ) . "</ins>";
  129.                             } else {
  130.                                 echo wc_price( $order_due[0]->shipping_tax_amount, array( 'currency' => $order_currency ) );
  131.                             }
  132.                             ?>
  133.                         </div>
  134.                     </td>
  135.                 </tr>
  136.                 <?php do_action( 'wcfm_vendor_order_details_after_shipping_tax', $order_id, $vendor_id ); ?>
  137.             <?php } ?>
  138.         <?php } ?>
  139.     <?php }
  140.  
  141. }, 10, 2 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement