Hey there guys,
we really love how clean your plugin is built, 10/10! However, we are currently facing an issue when trying to create multiple possible errors for making an offer. We have extended the errors with two new filters, they work great each on their own, however when using all of them simultaneously it leads to strange behavior, e.g.
Instead of saying that “Only hosts can make offers” (Rentalhive default) & “Please finalize your verification” it shows the confirmation message instead but doesn’t create the actual offer.
here is the current code:
/**
* MAKE OFFER: Restrict only to user with arbeitnehmer_complete = 1
*/
add_filter(
'hivepress/v1/forms/offer_make/errors',
function ($errors) {
$user_id = get_current_user_id();
$arbeitnehmer_complete = get_user_meta($user_id, 'arbeitnehmer_complete', true);
if ($arbeitnehmer_complete != 1) {
$errors[] = 'Bitte schließe zuerst die <a href="https://domain/verifizierung/">Verifizierung als Arbeitnehmer</a> ab.';
}
return $errors;
},
1000
);
/**
* MAKE OFFER: Restrict revenue treshold of 520€ total per month
*/
add_filter(
'hivepress/v1/forms/offer_make/errors',
function ($errors) {
$current_user_id = get_current_user_id();
// Get the current month and year
$current_month = date('m');
$current_year = date('Y');
// Get the first and last day of the current month
$date_after = date('Y-m-01'); // First day of the current month in 'YYYY-MM-DD' format
$date_before = date('Y-m-t'); // Last day of the current month in 'YYYY-MM-DD' format
// Get the vendor ID for the current user
$args = array(
'post_type' => 'hp_vendor',
'author' => $current_user_id,
'fields' => 'ids', // Only get post IDs
);
$vendor_ids = get_posts($args);
$vendor_id = $vendor_ids[0]; // Assuming each user has only one vendor
// Get the orders for the current month
$order_args = array(
'post_type' => 'shop_order',
'post_status' => array_keys(wc_get_order_statuses()),
'date_query' => array(
array(
'after' => $date_after,
'before' => $date_before,
'inclusive' => true,
),
),
'meta_query' => array(
array(
'key' => 'hp_vendor',
'value' => $vendor_id,
),
),
'posts_per_page' => -1,
);
$loop = new WP_Query($order_args);
// Calculate the total revenue
$woo_revenue = 0;
if ($loop->have_posts()) {
while ($loop->have_posts()) {
$loop->the_post();
$order = wc_get_order($loop->post->ID);
if ($order instanceof WC_Order) {
$woo_revenue += $order->get_total();
} else {
echo 'Invalid order ID: ' . $loop->post->ID . '<br>';
}
}
}
$woo_revenue *= 0.7824;
$user_side_income = floatval(get_user_meta($current_user_id, 'additional_earnings', true));
$total_revenue = $user_side_income + $woo_revenue;
if ($total_revenue > 520) {
$errors[] = 'Du hast die Monatsobergrenze von 520€ überschritten. Du kannst daher bis zum nächsten Monat keine neuen Jobs annehmen.';
}
return $errors;
},
1001
);
Any hints would be appreciated!
BR