I’m trying to require sellers to select from one attribute dropdown when creating a listing, but not allow selection of both:
add_filter(
'hivepress/v1/forms/listing_update/errors',
function( $errors, $form ) {
$listing = $form->get_model();
// Attempt to retrieve the values using direct property access
$service_1 = $listing->service_1;
$service_2 = $listing->service_2;
// Check if both fields are filled
if ($service_1 && $service_2) {
$errors[] = 'Please only fill out either "Service 1" or "Service 2", but not both.';
}
// Check if both fields are empty
if (!$service_1 && !$service_2) {
$errors[] = 'Please fill out one of the fields "Service 1" or "Service 2".';
}
return $errors;
},
100,
2
);
but I can’t seem to get it to work. I’m trying to check if both are selected, then send an error message and then check if neither are selected, then send an error message.
I’m at a loss.