palsushobhan

wcfmmp-view-refund-requests-popup.php

Jul 13th, 2021 (edited)
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.36 KB | None | 0 0
  1. <?php
  2. /**
  3.  * WCFM plugin view
  4.  *
  5.  * WCfM Refund popup View
  6.  *
  7.  * @author      WC Lovers
  8.  * @package     wcfmmp/views/refund
  9.  * @version   1.0.0
  10.  */
  11.  
  12. global $wp, $WCFM, $WCFMmp, $_POST, $wpdb;
  13.  
  14. $order_id      = sanitize_text_field( $_POST['order_id'] );
  15. $order_id = str_replace( '#', '', $order_id );
  16.  
  17. if( !$order_id ) return;
  18.  
  19. $item_id = 0;
  20. if( isset( $_POST['item_id'] ) ) {
  21.     $item_id       = sanitize_text_field( $_POST['item_id'] );
  22. }
  23.  
  24. $commission_id = 0;
  25. if( isset( $_POST['commission_id'] ) ) {
  26.     $commission_id = sanitize_text_field( $_POST['commission_id'] );
  27. }
  28.  
  29. $customer_refund = 'no';
  30. if( isset( $_POST['customer_refund'] ) ) {
  31.     $customer_refund = sanitize_text_field( $_POST['customer_refund'] );
  32. }
  33.  
  34.  
  35. $order                  = wc_get_order( $order_id );
  36. $order_taxes            = $order->get_taxes();
  37. $currency               = $order->get_currency();
  38.  
  39. $line_items             = $order->get_items( 'line_item' );
  40. if( $customer_refund != 'yes' ) {
  41.     $line_items             = apply_filters( 'wcfm_valid_line_items', $line_items, $order_id );
  42. }
  43.  
  44. $product_items          = array();
  45. foreach ( $line_items as $item_id => $item ) {
  46.     $order_item_id = $item->get_id();
  47.    
  48.     $refunded_amount = $order->get_total_refunded_for_item( $order_item_id );
  49.     $refunded_qty    = $order->get_qty_refunded_for_item( $order_item_id );
  50.     if( $refunded_qty ) $refunded_qty = ( $refunded_qty * -1 );
  51.    
  52.     $sql  = "SELECT ID, withdraw_status, vendor_id, refund_status, is_partially_refunded, is_refunded FROM {$wpdb->prefix}wcfm_marketplace_orders AS commission";
  53.     $sql .= " WHERE 1=1";
  54.     $sql .= " AND `item_id` = " . $order_item_id;
  55.     //$sql .= " AND (`is_refunded` = 1 OR `is_partially_refunded` = 1)";
  56.     //$sql .= " AND `refund_status` in ('completed', 'requested')";
  57.     $commissions = $wpdb->get_results( $sql );
  58.     if( !empty( $commissions ) ) {
  59.         foreach( $commissions as $commission ) {
  60.             if( ( $commission->is_refunded != 1 ) && ( $commission->refund_status != 'requested' ) && ( ( $commission->is_partially_refunded != 1 ) || ( ( $commission->is_partially_refunded == 1 ) && ( $commission->refund_status == 'completed' ) ) ) ) {
  61.                 $product_items[$order_item_id] = array( 'name' => $item->get_name(), 'cost' => $order->get_item_subtotal( $item, false, true ), 'qty' => ( $item->get_quantity() - $refunded_qty ), 'total' => ( $item->get_total() - $refunded_amount ), 'tax' => $item->get_taxes() );
  62.             }
  63.         }
  64.     } else {
  65.         $product_items[$order_item_id] = array( 'name' => $item->get_name(), 'cost' => $order->get_item_subtotal( $item, false, true ), 'qty' => ( $item->get_quantity() - $refunded_qty ), 'total' => ( $item->get_total() - $refunded_amount ), 'tax' => $item->get_taxes() );
  66.     }
  67. }
  68.  
  69. $request_mode = apply_filters( 'wcfm_refund_request_default_mode', 'partial' );
  70. ?>
  71.  
  72. <div class="wcfm-clearfix"></div><br />
  73. <div id="wcfm_refund_form_wrapper">
  74.     <form action="" method="post" id="wcfm_refund_requests_form" class="refund-form wcfm_popup_wrapper" novalidate="">
  75.         <div style="margin-bottom: 15px;"><h2 style="float: none;"><?php _e( 'Refund Request', 'wc-multivendor-marketplace' ); ?></h2></div>
  76.        
  77.         <?php if( !empty( $product_items ) ) { ?>
  78.            
  79.             <p class="wcfm-refund-form-request wcfm_popup_label">
  80.                 <label for="wcfm_refund_request"><strong><?php _e( 'Request Mode', 'wc-multivendor-marketplace' ); ?> <span class="required">*</span></strong></label>
  81.             </p>
  82.             <?php $WCFM->wcfm_fields->wcfm_generate_form_field( apply_filters( 'wcfm_refund_fields_request', array( "wcfm_refund_request" => array( 'type' => 'select', 'class' => 'wcfm-select wcfm_ele wcfm_popup_input', 'label_class' => 'wcfm_title', 'options' => array( 'full' => __( 'Full Refund', 'wc-multivendor-marketplace' ), 'partial' => __( 'Partial Refund', 'wc-multivendor-marketplace' ) ), 'value' => $request_mode ) ) ) ); ?>
  83.            
  84.             <div class="wcfm_clearfix"></div>
  85.             <div class="wcfm_refund_items_ele" style="margin-bottom: 15px;"><h2 style="float: none;"><?php _e( 'Refund by Item(s)', 'wc-multivendor-marketplace' ); ?></h2></div>
  86.             <div class="wcfm_clearfix"></div>
  87.            
  88.             <table cellpadding="0" cellspacing="0" class="woocommerce_order_items wcfm_refund_items_ele">
  89.                 <thead>
  90.                     <tr>
  91.                         <th class="item sortable" data-sort="string-ins"><?php _e( 'Item', 'wc-frontend-manager' ); ?></th>
  92.                         <th class="item_cost sortable no_mob" data-sort="float" style="text-align:center;"><?php _e( 'Cost', 'wc-frontend-manager' ); ?></th>
  93.                         <th class="item_quantity wcfm_item_qty_heading sortable" data-sort="int" style="text-align:center;"><?php _e( 'Qty', 'wc-frontend-manager' ); ?></th>
  94.                         <th class="line_cost sortable" data-sort="float" style="text-align:center;"><?php _e( 'Total', 'wc-frontend-manager' ); ?></th>
  95.                         <?php
  96.                             if ( wc_tax_enabled() && ! empty( $order_taxes ) ) :
  97.                                 foreach ( $order_taxes as $tax_id => $tax_item ) :
  98.                                     $column_label   = ! empty( $tax_item['label'] ) ? $tax_item['label'] : __( 'Tax', 'wc-frontend-manager' );
  99.                                     ?>
  100.                                     <th class="line_tax text_tip no_ipad no_mob" style="text-align:center;">
  101.                                         <?php echo esc_attr( $column_label ); ?>
  102.                                     </th>
  103.                                     <?php
  104.                                 endforeach;
  105.                             endif;
  106.                         ?>
  107.                     </tr>
  108.                 </thead>
  109.                 <tbody id="order_line_items">
  110.                     <?php if( !empty( $product_items ) ) { ?>
  111.                         <?php foreach( $product_items as $item_id => $product_item ) { $order_item = new WC_Order_Item_Product( $item_id ); ?>
  112.                             <tr class="order_line_item_<?php echo $item_id; ?>">
  113.                                 <td class="item sortable" data-sort="string-ins">
  114.                                   <?php
  115.                                   echo $product_item['name'];
  116.                                   do_action( 'woocommerce_order_item_meta_start', $item_id, $order_item, $order, false );
  117.                                     wc_display_item_meta( $order_item );
  118.                                     do_action( 'woocommerce_order_item_meta_end', $item_id, $order_item, $order, false );
  119.                                   ?>
  120.                                 </td>
  121.                                
  122.                                 <td class="item_cost sortable no_mob" data-sort="float" style="text-align:center;"><?php echo wc_price( $product_item['cost'], array( 'currency' => $currency ) ); ?></td>
  123.                                
  124.                                 <td class="item_quantity wcfm_item_qty_heading sortable" data-sort="int" style="text-align:center;">
  125.                                   <?php echo $product_item['qty']; ?><br />
  126.                                   <select class="wcfm_popup_input wcfm_refund_input_qty wcfm_refund_input_ele" data-item="<?php echo $item_id; ?>" name="wcfm_refund_input[<?php echo $item_id; ?>][qty]">
  127.                                     <option value="">0</option>
  128.                                     <?php for( $h = 1; $h <= $product_item['qty']; $h++ ) { ?>
  129.                                         <option value="<?php echo $h; ?>"><?php echo $h; ?></option>
  130.                                     <?php } ?>
  131.                                   </select>
  132.                                   <input type="hidden" value="<?php echo $item_id; ?>" name="wcfm_refund_input[<?php echo $item_id; ?>][item]">
  133.                                 </td>
  134.                                
  135.                                 <td class="line_cost sortable" data-sort="float" style="text-align:center;">
  136.                                   <?php echo wc_price( $product_item['total'], array( 'currency' => $currency ) ); ?><br />
  137.                                   <input type="number" readonly class="wcfm_popup_input wcfm_refund_input_total wcfm_refund_input_ele" data-item_cost="<?php echo round( $product_item['total']/$product_item['qty'], 2 ); ?>" name="wcfm_refund_input[<?php echo $item_id; ?>][total]" min="0" step="1" max="<?php echo $product_item['total']; ?>" data-max_total="<?php echo $product_item['total']; ?>"  />
  138.                                 </td>
  139.                                
  140.                                 <?php
  141.                                     if ( wc_tax_enabled() ) {
  142.                                         $tax_data = $product_item['tax'];
  143.                                         if ( ! empty( $tax_data ) ) {
  144.                                             foreach ( $order_taxes as $tax_item ) {
  145.                                                 $tax_item_id       = $tax_item['rate_id'];
  146.                                                 $tax_item_total    = isset( $tax_data['total'][ $tax_item_id ] ) ? $tax_data['total'][ $tax_item_id ] : 0;
  147.                                                 if( !is_numeric( $tax_item_total ) ) $tax_item_total = 0;
  148.                                                 $tax_item_subtotal = isset( $tax_data['subtotal'][ $tax_item_id ] ) ? $tax_data['subtotal'][ $tax_item_id ] : 0;
  149.                                                 $refunded = $order->get_tax_refunded_for_item( $item_id, $tax_item_id );
  150.                                                 if( !is_numeric( $refunded ) ) $refunded = 0;
  151.                                                 $tax_cost = ( $tax_item_total - $refunded );
  152.                                                 ?>
  153.                                                 <td class="line_tax no_ipad no_mob" style="text-align:center;">
  154.                                                     <div class="view">
  155.                                                         <?php
  156.                                                             if ( '' != $tax_item_total ) {
  157.                                                                 echo wc_price( wc_round_tax_total( $tax_cost ), array( 'currency' => $currency ) );
  158.                                                                 ?><br />
  159.                                                                 <span id="wcfm_refund_item_tax_cost"></span>
  160.                                                                 <input type="number" readonly class="wcfm_popup_input wcfm_refund_input_tax wcfm_refund_input_ele" data-item_tax="<?php echo round( $tax_cost/$product_item['qty'], 2 ); ?>" name="wcfm_refund_tax_input[<?php echo $item_id; ?>][<?php echo $tax_item_id; ?>]" min="0" step="1" max="<?php echo $tax_cost; ?>" data-max_tax="<?php echo $tax_cost; ?>"  />
  161.                                                                 <?php
  162.                                                             } else {
  163.                                                                 echo '&ndash;';
  164.                                                             }
  165.                                                         ?>
  166.                                                     </div>
  167.                                                 </td>
  168.                                                 <?php
  169.                                             }
  170.                                         }
  171.                                     }
  172.                                 ?>
  173.                             </tr>
  174.                         <?php } ?>
  175.                     <?php } ?>
  176.                 </tbody>
  177.             </table>
  178.            
  179.             <div class="wcfm_clearfix"></div>
  180.             <p class="wcfm-refund-form-reason wcfm_popup_label">
  181.                 <label for="comment"><strong><?php _e( 'Refund Requests Reason', 'wc-multivendor-marketplace' ); ?> <span class="required">*</span></strong></label>
  182.             </p>
  183.             <textarea id="wcfm_refund_reason" name="wcfm_refund_reason" class="wcfm_popup_input wcfm_popup_textarea"></textarea>
  184.             <div class="wcfm_clearfix"></div>
  185.        
  186.             <?php if ( function_exists( 'gglcptch_init' ) ) { ?>
  187.             <div class="wcfm_clearfix"></div>
  188.             <div class="wcfm_gglcptch_wrapper" style="float:right;">
  189.                 <?php echo apply_filters( 'gglcptch_display_recaptcha', '', 'wcfm_refund_request_form' ); ?>
  190.             </div>
  191.         <?php } elseif ( class_exists( 'anr_captcha_class' ) && function_exists( 'anr_captcha_form_field' ) ) { ?>
  192.             <div class="wcfm_clearfix"></div>
  193.             <div class="wcfm_gglcptch_wrapper" style="float:right;">
  194.                 <div class="anr_captcha_field"><div id="anr_captcha_field_9999"></div></div>
  195.                            
  196.                 <?php
  197.                     $site_key = trim( anr_get_option( 'site_key' ) );
  198.                     $theme    = anr_get_option( 'theme', 'light' );
  199.                     $size     = anr_get_option( 'size', 'normal' );
  200.                     $language = trim( anr_get_option( 'language' ) );
  201.        
  202.                         $lang = '';
  203.                     if ( $language ) {
  204.                         $lang = "&hl=$language";
  205.                     }
  206.        
  207.                 ?>
  208.                 <script type="text/javascript">
  209.                     var wcfm_refund_anr_onloadCallback = function() {
  210.                         var anr_obj = {
  211.                         'sitekey' : '<?php echo esc_js( $site_key ); ?>',
  212.                         'size' : '<?php echo esc_js( $size ); ?>',
  213.                     };
  214.                     <?php
  215.                     if ( 'invisible' == $size ) {
  216.                         wp_enqueue_script( 'jquery' );
  217.                         ?>
  218.                         anr_obj.badge = '<?php echo esc_js( anr_get_option( 'badge', 'bottomright' ) ); ?>';
  219.                     <?php } else { ?>
  220.                         anr_obj.theme = '<?php echo esc_js( $theme ); ?>';
  221.                     <?php } ?>
  222.                
  223.                         var anr_captcha9999;
  224.                        
  225.                         <?php if ( 'invisible' == $size ) { ?>
  226.                             var anr_form9999 = jQuery('#anr_captcha_field_9999').closest('form')[0];
  227.                             anr_obj.callback = function(){ anr_form9999.submit(); };
  228.                             anr_obj["expired-callback"] = function(){ grecaptcha.reset(anr_captcha9999); };
  229.                            
  230.                             anr_form9999.onsubmit = function(evt){
  231.                                 evt.preventDefault();
  232.                                 //grecaptcha.reset(anr_captcha9999);
  233.                                 grecaptcha.execute(anr_captcha9999);
  234.                             };
  235.                         <?php } ?>
  236.                         anr_captcha_9999 = grecaptcha.render('anr_captcha_field_9999', anr_obj );
  237.                     };
  238.                 </script>
  239.                 <script src="https://www.google.com/recaptcha/api.js?render=explicit<?php echo esc_js( $lang ); ?>"
  240.                     async defer>
  241.                 </script>
  242.             </div>
  243.         <?php } ?>
  244.             <div class="wcfm_clearfix"></div>
  245.             <div class="wcfm-message" tabindex="-1"></div>
  246.             <div class="wcfm_clearfix"></div><br />
  247.            
  248.             <p class="form-submit">
  249.                 <input name="submit" type="submit" id="wcfm_refund_requests_submit_button" class="submit wcfm_popup_button" value="<?php _e( 'Submit', 'wc-multivendor-marketplace' ); ?>">
  250.                 <input type="hidden" name="wcfm_refund_order_id" value="<?php echo $order_id; ?>" id="wcfm_refund_order_id">
  251.             </p>   
  252.         <?php } else { ?>
  253.             <div><?php _e( 'This order\'s item(s) are already requested for refund!', 'wc-multivendor-marketplace' ); ?></div>
  254.         <?php } ?>
  255.         <div class="wcfm-clearfix"></div>
  256.     </form>
  257.     <div class="wcfm-clearfix"></div>
  258. </div>
  259. <div class="wcfm-clearfix"></div>
Add Comment
Please, Sign In to add comment