Untitled

mail@pastecode.io avatar
unknown
plain_text
17 days ago
1.3 kB
1
Indexable
Never
add_filter('b2bking_group_rules_monthly_spent', function($monthly_spent, $user_id){
			    	// add affiliate sales
			    	$group_rules_args = apply_filters('salesking_group_rules_args', array( 
			    	    'post_type' => 'salesking_earning',
			    	    'numberposts' => -1,
			    	    'post_status'    => 'any',
			    	    'fields'    => 'ids',
			    	    'meta_key'   => 'agent_id',
			    	    'meta_value' => $user_id,
			    	), $user_id);
			    	// get total agent commissions
			    	$earnings = get_posts( $group_rules_args );

			    	$total_agent_commissions = 0;
			    	$total_orders_amount = 0;

			    	foreach ($earnings as $earning_id){
			    	    $order_id = get_post_meta($earning_id,'order_id', true);
			    	    $orderobj = wc_get_order($order_id);
			    	    if ($orderobj !== false){
			    		    $earnings_total = get_post_meta($earning_id,'salesking_commission_total', true);
			    		    if (!empty($earnings_total) && floatval($earnings_total) !== 0){
			    		        $status = $orderobj->get_status();
			    		        $order_total = $orderobj->get_total();

			    		        $total_agent_commissions+=$earnings_total;
			    		        $total_orders_amount += $order_total;

			    		    }
			    		}
			    	}

			    	$monthly_spent += $total_agent_commissions;

			    	return $monthly_spent;
			    }, 10, 2);
Leave a Comment