Hi there,
is anybody still on this topic, ’cause I’m trying to figure out the same problem.
More specifically, the contact form is to enquire about the vacancy of hotel room.
For each room, I need to know how many people/pets are going to be in that room.
Of course, there is a limit to it, and that is 4 people/pets.
I’d like to insert an error message anytime they try to book a room for more than 4 people/pets.
My last – unsuccessful – attemp was the following code:
add_filter( 'wpcf7_max_capacity*', 'custom_max_capacity_validation_filter', 20, 2 );
function custom_max_capacity_validation_filter( $result, $tag, $zero, $adults, $children, $babies, $pets ) {
$tag = new WPCF7_FormTag( $tag );
$zero = "0";
if ( 'r1-adults' == $tag->name AND 'r1-children' == $tag->name AND 'r1-babies' == $tag->name AND 'r1-pets' == $tag->name ) {
$adults = isset( $_POST['r1-adults'] ) ? settype(trim( $_POST['r1-adults'] ), "integer") : settype($zero, "integer");
$children = isset( $_POST['r1-children'] ) ? settype(trim( $_POST['r1-children'] ), "integer") : settype($zero, "integer");
$babies = isset( $_POST['r1-babies'] ) ? settype(trim( $_POST['r1-babies'] ), "integer") : settype($zero, "integer");
$pets = isset( $_POST['r1-pets'] ) ? settype(trim( $_POST['r1-pets'] ), "integer") : settype($zero, "integer");
$sum=$adults+$children+$babies+$pets;
if ($sum > 4 ) {
$result->invalidate( $tag, "Max occupancy per room: 4 people/pets" );
}
}
return $result;
}
Any idea how to fix it?
Thanks!