Withdrawl of commission on Booking Complete
-
Hi,
I’m using woocommerce booking along with WCFM & I want the comission to be automatically withdraw on booking status set to completed. Right now the automatical withdrawl works if the order status is completed but in my case there are multiple booking in single order so I want I want is the auto-withdrawl of commission to worked on Booking status set to complete.
I searched wcfm forums & i found 1 code but it’s not working.
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 );
Thank you
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Withdrawl of commission on Booking Complete’ is closed to new replies.