Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.3 kB
1
Indexable
Never
add_filter('salesking_group_rules_allowed_statuses', function($statuses){
	$statuses = array('on-hold', 'processing');
	return $statuses;
}, 10, 1);
add_filter('salesking_group_rules_args', function($args, $agent_id){
	
	$first_day_of_month = date('Y-m-01', current_time('timestamp'));

    $args = array(
        'post_type' => 'salesking_earning',
        'numberposts' => -1,
        'post_status' => 'any',
        'fields' => 'ids',
        'meta_key' => 'agent_id',
        'meta_value' => $agent_id,
        'date_query' => array(
            array(
                'after' => $first_day_of_month,
                'inclusive' => true
            )
        )
    );
    return $args;
}, 10, 2);

add_filter('salesking_group_rules_args_parent', function($args, $agent_id){
	
	$first_day_of_month = date('Y-m-01', current_time('timestamp'));

    $args = array(
        'post_type' => 'salesking_earning',
        'numberposts' => -1,
        'post_status' => 'any',
        'fields' => 'ids',
        'meta_key'   => 'parent_agent_id_'.$agent_id,
		'meta_value' => $agent_id,
        'date_query' => array(
            array(
                'after' => $first_day_of_month,
                'inclusive' => true
            )
        )
    );
    return $args;
}, 10, 2);

if ( ! wp_next_scheduled( 'my_monthly_agent_update' ) ) {
  wp_schedule_event( strtotime('first day of next month midnight'), 'monthly', 'my_monthly_agent_update' );
}
function update_agent_salesking_group() {
    $agents = get_users(array(
        'meta_key'     => 'salesking_group',
        'meta_value'   => 'none',
        'meta_compare' => '!=',
        'fields' => 'ids',
    ));

    foreach ($agents as $agent_id) {
        update_user_meta($agent_id, 'salesking_group', 330);
    }
}
add_action( 'my_monthly_agent_update', 'update_agent_salesking_group' );

add_filter('salesking_earnings_total_threshold',function($val){
	return -1;
}, 10, 1);

add_action('salesking_after_calculated_earnings', function($order_id, $current_user_id){
	$order = wc_get_order($order_id);
	if ($order){

		$earning_id_check = $order->get_meta('salesking_earning_id');
		$commission_value = get_post_meta($earning_id_check, 'salesking_commission_total', true);
		if ($commission_value < 0.1){
			update_post_meta($earning_id_check, 'salesking_commission_total', 0);
		}
	}
}, 10, 2);
Leave a Comment