Link commission withdrawal to booking statuses

We're shifting our Forum based support to a more dedicated support system!

We'll be closing our Forum support from 10th June, 2020 and move to Email Support assistance.

  • If you are a WCFM premium add-ons user, contact us- here
  • Want to know more before buying our add-ons? Send Pre sale queries- here
  • If you are a WCFM free user, please open a support ticket at WordPress.org
  • For WCFM App related queries, reach us- here
From now the forum will be read-only!

Multi Vendor Marketplace Plugin | WCFM Marketplace Forums WC Bookings Link commission withdrawal to booking statuses

Viewing 5 reply threads
  • Author
    Posts
    • #41387
      hello4
      Participant

      Hello,

      I have a setup with WC+WC Bookings+WCPV which I am planning to migrate to your WCMM plugin. Currently my setup allows multiple bookings (products from multiple vendors) to be placed on a single order. With this setup, if we use the ‘order statuses’ to determine the commission withdrawal for vendors, every vendor has to wait until all bookings on a order to be completed and the order to be marked as completed to request their commissions. Is there a way that we can link the withdrawal eligibility to ‘booking statuses’ instead of ‘order statuses’?

      Many thanks in advance!

    • #41393
      WCFM Forum
      Keymaster

      Hi,

      Yeah possible.

      For which booking status you want to generate withdrawal request?

      Thank You

    • #41444
      hello4
      Participant

      Hello,

      It could be either ‘Complete’ or ‘Delivered’ (it’s a custom booking status).

      Thanks and in advance.

    • #41468
      WCFM Forum
      Keymaster

      OK fine, I will give you a code snippet for this in few hours.

      Thank You

    • #41797
      hello4
      Participant

      Hello again,

      Any updates on this?

      Thanks and regards,

    • #42292
      WCFM Forum
      Keymaster

      Hi,

      Here is your custom code –

      function wcfmmp_generate_auto_withdrawal_on_booking_status( $booking_id, $booking ) {
      	global $WCFM, $WCFMmp, $wpdb;
      	
      	if( !$WCFM || !$WCFMmp ) return;
      	
      	$order    = $booking->get_order();
      	$order_id = $order->get_id();
      	
      	$sql = 'SELECT GROUP_CONCAT(ID) commission_ids, COALESCE( SUM( commission.total_commission ), 0 ) AS total_commission, vendor_id, withdraw_status, order_status  FROM ' . $wpdb->prefix . 'wcfm_marketplace_orders AS commission';
      	$sql .= ' WHERE 1=1';
      	$sql .= " AND <code>order_id</code> = " . $order_id;
      	$sql .= " GROUP BY vendor_id";
      	$commission_infos = $wpdb->get_results( $sql );
      	
      	if( !empty( $commission_infos ) ) {
      		foreach( $commission_infos as $commission_info ) {
      			
      			if( $commission_info->withdraw_status != 'pending' ) continue;
      			//if( $commission_info->order_status == $auto_withdrawal_status ) continue;
      			
      			$vendor_id = absint($commission_info->vendor_id);
      			
      			$payment_method = $WCFMmp->wcfmmp_vendor->get_vendor_payment_method( $vendor_id );
      			if( !$payment_method ) continue;
      			
      			// Reset Commission withdrawal charges as per total withdrawal charge
      			$withdraw_charges = $WCFMmp->wcfmmp_withdraw->calculate_withdrawal_charges( $commission_info->total_commission, $vendor_id );
      			
      			// Update Commission withdrawal Status
      			$commissions = explode( ",", $commission_info->commission_ids );
      			$no_of_commission = count($commissions);
      			$withdraw_charge_per_commission = (float)$withdraw_charges/$no_of_commission;
      			foreach( $commissions as $commission_id ) {
      				$wpdb->update("{$wpdb->prefix}wcfm_marketplace_orders", array('withdraw_status' => 'requested', 'withdraw_charges' => round($withdraw_charge_per_commission,2)), array('ID' => $commission_id), array('%s', '%s'), array('%d'));
      			}
      			
      			$withdraw_request_id = $WCFMmp->wcfmmp_withdraw->wcfmmp_withdrawal_processed( $vendor_id, $order_id, $commission_info->commission_ids, $payment_method, 0, $commission_info->total_commission, $withdraw_charges, 'requested', 'by_auto_request' );
      			
      			if( $withdraw_request_id && !is_wp_error( $withdraw_request_id ) ) {
      				$is_auto_approve = $WCFMmp->wcfmmp_withdraw->is_withdrawal_auto_approve( $vendor_id );
      				if( $is_auto_approve ) {
      					$payment_processesing_status = $WCFMmp->wcfmmp_withdraw->wcfmmp_withdrawal_payment_processesing( $withdraw_request_id, $vendor_id, $payment_method, $commission_info->total_commission, $withdraw_charges );
      					if( $payment_processesing_status ) {
      						//wcfm_log( __('Auto Withdrawal Request successfully processed.', 'wc-multivendor-marketplace') . ': #' . sprintf( '%06u', $withdraw_request_id ) );
      					} else {
      						wcfm_log( __('Auto Withdrawal Request processing failed, please contact Store Admin.', 'wc-multivendor-marketplace') . ': #' . sprintf( '%06u', $withdraw_request_id ) );
      					}
      				} else {
      					// Admin Notification
      					$shop_name = $WCFM->wcfm_vendor_support->wcfm_get_vendor_store_by_vendor( absint($vendor_id) );
      					$wcfm_messages = sprintf( __( 'Vendor <b>%s</b> has placed a Withdrawal Request #%s.', 'wc-multivendor-marketplace' ), $shop_name, '<a target="_blank" class="wcfm_dashboard_item_title" href="' . add_query_arg( 'transaction_id', $withdraw_request_id, wcfm_withdrawal_requests_url() ) . '">' . sprintf( '%06u', $withdraw_request_id ) . '</a>' );
      					$WCFM->wcfm_notification->wcfm_send_direct_message( $vendor_id, 0, 0, 1, $wcfm_messages, 'withdraw-request' );
      					//wcfm_log( __('Auto withdrawal request successfully sent.', 'wc-frontend-manager') . ': #' . sprintf( '%06u', $withdraw_request_id ) );
      				}
      				
      				do_action( 'wcfmmp_withdrawal_request_submited', $withdraw_request_id, $vendor_id );
      			} else {
      				wcfm_log( __('Auto withdrawal request failed, please try after sometime.', 'wc-multivendor-marketplace') );
      			}
      		}
      	}
      }
      add_action( 'woocommerce_booking_complete', 'wcfmmp_generate_auto_withdrawal_on_booking_status', 50, 2 );

      Well, I have written this only for “complete” status.

      Ad such a line for your custom status and replace “complete” word with your custom status slug – add_action( ‘woocommerce_booking_complete’ ‘wcfmmp_generate_auto_withdrawal_on_booking_status’, 50, 2 );

      Thank You

Viewing 5 reply threads
  • The topic ‘Link commission withdrawal to booking statuses’ is closed to new replies.