Advertisement
wclovers

Untitled

Jan 10th, 2022
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.92 KB | None | 0 0
  1. add_action( 'wcfm_init', function() {
  2.     global $WCFMmp;
  3.     if( wcfm_is_vendor() ) {
  4.         if( has_filter( 'wcfmmarketplace_orders_actions', array( $WCFMmp->wcfmmp_refund, 'wcfmmp_refund_orders_actions' ) ) ) {
  5.             remove_filter( 'wcfmmarketplace_orders_actions', array( $WCFMmp->wcfmmp_refund, 'wcfmmp_refund_orders_actions' ), 100 );
  6.             add_filter( 'wcfmmarketplace_orders_actions', 'wcfmmp_refund_orders_actions_modified', 100, 4 );
  7.         }
  8.     }
  9. }, 12 );
  10.  
  11. function wcfmmp_refund_orders_actions_modified( $actions, $vendor_id, $order, $the_order ) {
  12.     global $WCFM, $WCFMmp;
  13.    
  14.     $order_status = sanitize_title( $the_order->get_status() );
  15.     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;
  16.    
  17.     if( !apply_filters( 'wcfm_is_allow_refund_requests', true ) ) return $actions;
  18.     if( !apply_filters( 'wcfm_is_allow_paid_order_refund', false ) && ($order->withdraw_status != 'pending') && !in_array( $the_order->get_payment_method(), array( 'wirecard', 'stripe_split' ) ) ) return $actions;
  19.      
  20.     $refund_statuses = explode( ",", $order->refund_statuses );
  21.     //if( in_array( 'requested', $refund_statuses ) ) return $actions;
  22.    
  23.     $is_refundeds = explode( ",", $order->is_refundeds );
  24.     if( !in_array( 0, $is_refundeds ) ) return $actions;
  25.    
  26.     // Refund Threshold check
  27.     $refund_threshold = isset( $WCFMmp->wcfmmp_refund_options['refund_threshold'] ) ? $WCFMmp->wcfmmp_refund_options['refund_threshold'] : '';
  28.     if( $refund_threshold ) {
  29.         $current_time = strtotime( 'midnight', current_time( 'timestamp' ) );
  30.         $date = date( 'Y-m-d', $current_time );
  31.         $created_date = date( 'Y-m-d', strtotime($order->created) );
  32.         $datetime1 = new DateTime( $date );
  33.         $datetime2 = new DateTime( $created_date );
  34.         $interval = $datetime2->diff( $datetime1 );
  35.         $interval = $interval->format( '%r%a' );
  36.         if( ( (int) $interval >= 0 ) && ( (int) $interval > (int) $refund_threshold ) ) return $actions;
  37.     }
  38.  
  39.     $wc_order = wc_get_order( $order->order_id );
  40.     if( $wc_order && is_a( $wc_order , 'WC_Order' ) ) {
  41.         $created_via = $wc_order->get_created_via();
  42.         if( $created_via && in_array( $created_via, apply_filters( 'wcfmmp_new_order_check_created_via', array( 'rest-api' ) ) ) ) {
  43.             return $actions;
  44.         }
  45.     }
  46.      
  47.     $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>';
  48.    
  49.     return $actions;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement