Multi Vendor Marketplace Plugin | WCFM Marketplace › Forums › WC Bookings › Link commission withdrawal to booking statuses
Tagged: booking status, Commission, order status, WooCommerce bookings, woocommerce multivendor marketplace
- This topic has 5 replies, 2 voices, and was last updated 5 years, 10 months ago by WCFM Forum.
- AuthorPosts
- December 27, 2018 at 1:32 pm #41387hello4Participant
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!
- December 27, 2018 at 2:02 pm #41393WCFM ForumMember
Hi,
Yeah possible.
For which booking status you want to generate withdrawal request?
Thank You
- December 27, 2018 at 5:40 pm #41444hello4Participant
Hello,
It could be either ‘Complete’ or ‘Delivered’ (it’s a custom booking status).
Thanks and in advance.
- December 28, 2018 at 5:56 am #41468WCFM ForumMember
OK fine, I will give you a code snippet for this in few hours.
Thank You
- December 31, 2018 at 11:33 am #41797hello4Participant
Hello again,
Any updates on this?
Thanks and regards,
- January 5, 2019 at 9:44 am #42292WCFM ForumMember
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
- AuthorPosts
- The topic ‘Link commission withdrawal to booking statuses’ is closed to new replies.