Advertisement
wclovers

Untitled

Mar 28th, 2023
565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.31 KB | None | 0 0
  1. add_filter('wcfmmarketplace_orders_actions', function ( $actions, $vendor_id, $order, $the_order ) {
  2.     global $WCFMmp;
  3.    
  4.     if (wcfm_is_vendor()) {
  5.         remove_filter('wcfmmarketplace_orders_actions', array($WCFMmp->wcfmmp_refund, 'wcfmmp_refund_orders_actions'), 100, 4);
  6.        
  7.         global $WCFM, $WCFMmp;
  8.  
  9.         $order_status = sanitize_title($the_order->get_status());
  10.         if (in_array($order_status, apply_filters('wcfm_refund_disable_order_status', array('failed', 'cancelled', 'refunded', 'pending', 'on-hold', 'request', 'proposal', 'proposal-sent', 'proposal-expired', 'proposal-rejected', 'proposal-canceled', 'proposal-accepted')))) return $actions;
  11.  
  12.         if (!apply_filters('wcfm_is_allow_refund_requests', true)) return $actions;
  13.         if (!apply_filters('wcfm_is_allow_paid_order_refund', false) && ($order->withdraw_status != 'pending') && !in_array($the_order->get_payment_method(), apply_filters('wcfm_enabled_payment_gateways_for_order_refund_action', array('wirecard', 'stripe_split')))) return $actions;
  14.  
  15.         $refund_statuses = explode(",", $order->refund_statuses);
  16.  
  17.         $is_refundeds = explode(",", $order->is_refundeds);
  18.         if (!in_array(0, $is_refundeds)) return $actions;
  19.  
  20.         // Refund Threshold check
  21.         $refund_threshold = isset($WCFMmp->wcfmmp_refund_options['refund_threshold']) ? $WCFMmp->wcfmmp_refund_options['refund_threshold'] : '';
  22.         if ($refund_threshold) {
  23.             $current_time = strtotime('midnight', current_time('timestamp'));
  24.             $date = date('Y-m-d', $current_time);
  25.             $completed_date = date('Y-m-d', strtotime($the_order->get_date_completed()));
  26.             $datetime1 = new DateTime($date);
  27.             $datetime2 = new DateTime($completed_date);
  28.             $interval = $datetime2->diff($datetime1);
  29.             $interval = $interval->format('%r%a');
  30.             if (((int) $interval >= 0) && ((int) $interval > (int) $refund_threshold)) return $actions;
  31.         }
  32.  
  33.         $actions .= '<a class="wcfmmp_order_refund_request wcfm-action-icon" href="#" data-item="' . $order->item_id . '" data-commission="' . $order->ID . '" data-order="' . $order->order_id . '"><span class="wcfmfa fa-retweet text_tip" data-tip="' . esc_attr__('Refund Request', 'wc-multivendor-marketplace') . '"></span></a>';
  34.  
  35.         return $actions;
  36.     }
  37. }, 99, 4);
  38.  
  39. add_filter('woocommerce_my_account_my_orders_actions', function ($actions, $order) {
  40.     global $WCFM, $WCFMmp, $wpdb;
  41.  
  42.     add_filter('woocommerce_my_account_my_orders_actions', array($WCFMmp->wcfmmp_refund, 'wcfmmp_myaccount_refund_order_action'), 110, 2);
  43.  
  44.     if (!apply_filters('wcfm_is_allow_customer_refund', true)) return $actions;
  45.  
  46.     $refund_by_customer = isset($WCFMmp->wcfmmp_refund_options['refund_by_customer']) ? $WCFMmp->wcfmmp_refund_options['refund_by_customer'] : 'no';
  47.     if ($refund_by_customer == 'no') return $actions;
  48.  
  49.     $order_id = $order->get_id();
  50.  
  51.     $wcfm_refund_request = get_post_meta($order_id, '_wcfm_refund_request', true);
  52.     if ($wcfm_refund_request) return $actions;
  53.  
  54.     $order_status = sanitize_title($order->get_status());
  55.     if (in_array($order_status, apply_filters('wcfm_refund_disable_order_status', array('failed', 'cancelled', 'refunded', 'pending', 'on-hold', 'request', 'proposal', 'proposal-sent', 'proposal-expired', 'proposal-rejected', 'proposal-canceled', 'proposal-accepted')))) return $actions;
  56.  
  57.     $withdraw_status  = 'pending';
  58.     $refund_status    = '';
  59.     $vendor_id        = 0;
  60.     $is_refunded      = 0;
  61.  
  62.     $sql = 'SELECT ID, withdraw_status, vendor_id, refund_status, is_refunded FROM ' . $wpdb->prefix . 'wcfm_marketplace_orders AS commission';
  63.     $sql .= ' WHERE 1=1';
  64.     $sql .= " AND `order_id` = %d";
  65.     $commissions = $wpdb->get_results($wpdb->prepare($sql, $order_id));
  66.     if (!empty($commissions)) {
  67.         foreach ($commissions as $commission) {
  68.             $withdraw_status  = $commission->withdraw_status;
  69.             $vendor_id        = $commission->vendor_id;
  70.             $refund_status    = $commission->refund_status;
  71.             $is_refunded      = $commission->is_refunded;
  72.  
  73.             if (!$is_refunded && ($refund_status != 'requested')) break;
  74.         }
  75.     }
  76.  
  77.     //if( $withdraw_status != 'pending' ) return $actions;
  78.     if ($refund_status == 'requested') return $actions;
  79.     if ($is_refunded) return $actions;
  80.  
  81.     // Refund Threshold check
  82.     $refund_threshold = isset($WCFMmp->wcfmmp_refund_options['refund_threshold']) ? $WCFMmp->wcfmmp_refund_options['refund_threshold'] : '';
  83.     if ($refund_threshold) {
  84.         $current_time = strtotime('midnight', current_time('timestamp'));
  85.         $date = date('Y-m-d', $current_time);
  86.         $order_date = (version_compare(WC_VERSION, '2.7', '<')) ? $order->date_completed : $order->get_date_completed();
  87.         $completed_date = date('Y-m-d', strtotime($order_date));
  88.         $datetime1 = new DateTime($date);
  89.         $datetime2 = new DateTime($completed_date);
  90.         $interval = $datetime2->diff($datetime1);
  91.         $interval = $interval->format('%r%a');
  92.         if (((int) $interval >= 0) && ((int) $interval > (int) $refund_threshold)) return $actions;
  93.     }
  94.  
  95.     $actions['wcfm-refund-action'] = array('name' => __('Refund', 'wc-multivendor-marketplace'), 'url' => '#' . $order_id);
  96.     return $actions;
  97. }, 109, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement