Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter('wcfmmarketplace_orders_actions', function ( $actions, $vendor_id, $order, $the_order ) {
- global $WCFMmp;
- if (wcfm_is_vendor()) {
- remove_filter('wcfmmarketplace_orders_actions', array($WCFMmp->wcfmmp_refund, 'wcfmmp_refund_orders_actions'), 100, 4);
- global $WCFM, $WCFMmp;
- $order_status = sanitize_title($the_order->get_status());
- 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;
- if (!apply_filters('wcfm_is_allow_refund_requests', true)) return $actions;
- 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;
- $refund_statuses = explode(",", $order->refund_statuses);
- $is_refundeds = explode(",", $order->is_refundeds);
- if (!in_array(0, $is_refundeds)) return $actions;
- // Refund Threshold check
- $refund_threshold = isset($WCFMmp->wcfmmp_refund_options['refund_threshold']) ? $WCFMmp->wcfmmp_refund_options['refund_threshold'] : '';
- if ($refund_threshold) {
- $current_time = strtotime('midnight', current_time('timestamp'));
- $date = date('Y-m-d', $current_time);
- $completed_date = date('Y-m-d', strtotime($the_order->get_date_completed()));
- $datetime1 = new DateTime($date);
- $datetime2 = new DateTime($completed_date);
- $interval = $datetime2->diff($datetime1);
- $interval = $interval->format('%r%a');
- if (((int) $interval >= 0) && ((int) $interval > (int) $refund_threshold)) return $actions;
- }
- $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>';
- return $actions;
- }
- }, 99, 4);
- add_filter('woocommerce_my_account_my_orders_actions', function ($actions, $order) {
- global $WCFM, $WCFMmp, $wpdb;
- add_filter('woocommerce_my_account_my_orders_actions', array($WCFMmp->wcfmmp_refund, 'wcfmmp_myaccount_refund_order_action'), 110, 2);
- if (!apply_filters('wcfm_is_allow_customer_refund', true)) return $actions;
- $refund_by_customer = isset($WCFMmp->wcfmmp_refund_options['refund_by_customer']) ? $WCFMmp->wcfmmp_refund_options['refund_by_customer'] : 'no';
- if ($refund_by_customer == 'no') return $actions;
- $order_id = $order->get_id();
- $wcfm_refund_request = get_post_meta($order_id, '_wcfm_refund_request', true);
- if ($wcfm_refund_request) return $actions;
- $order_status = sanitize_title($order->get_status());
- 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;
- $withdraw_status = 'pending';
- $refund_status = '';
- $vendor_id = 0;
- $is_refunded = 0;
- $sql = 'SELECT ID, withdraw_status, vendor_id, refund_status, is_refunded FROM ' . $wpdb->prefix . 'wcfm_marketplace_orders AS commission';
- $sql .= ' WHERE 1=1';
- $sql .= " AND `order_id` = %d";
- $commissions = $wpdb->get_results($wpdb->prepare($sql, $order_id));
- if (!empty($commissions)) {
- foreach ($commissions as $commission) {
- $withdraw_status = $commission->withdraw_status;
- $vendor_id = $commission->vendor_id;
- $refund_status = $commission->refund_status;
- $is_refunded = $commission->is_refunded;
- if (!$is_refunded && ($refund_status != 'requested')) break;
- }
- }
- //if( $withdraw_status != 'pending' ) return $actions;
- if ($refund_status == 'requested') return $actions;
- if ($is_refunded) return $actions;
- // Refund Threshold check
- $refund_threshold = isset($WCFMmp->wcfmmp_refund_options['refund_threshold']) ? $WCFMmp->wcfmmp_refund_options['refund_threshold'] : '';
- if ($refund_threshold) {
- $current_time = strtotime('midnight', current_time('timestamp'));
- $date = date('Y-m-d', $current_time);
- $order_date = (version_compare(WC_VERSION, '2.7', '<')) ? $order->date_completed : $order->get_date_completed();
- $completed_date = date('Y-m-d', strtotime($order_date));
- $datetime1 = new DateTime($date);
- $datetime2 = new DateTime($completed_date);
- $interval = $datetime2->diff($datetime1);
- $interval = $interval->format('%r%a');
- if (((int) $interval >= 0) && ((int) $interval > (int) $refund_threshold)) return $actions;
- }
- $actions['wcfm-refund-action'] = array('name' => __('Refund', 'wc-multivendor-marketplace'), 'url' => '#' . $order_id);
- return $actions;
- }, 109, 2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement