Skip to content

Instantly share code, notes, and snippets.

@NateWr
Last active August 18, 2018 11:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NateWr/b015b059bba49bea67fb to your computer and use it in GitHub Desktop.
Save NateWr/b015b059bba49bea67fb to your computer and use it in GitHub Desktop.
Remove the party field from your Restaurant Reservations booking form.
<?php
/**
* Plugin Name: Remove Party Field for Restaurant Reservations
* Plugin URI: http://themeofthecrop.com
* Description: Removes the party field and prevents the associated errors from occurring.
* Version: 1.0
* Author: Theme of the Crop
* Author URI: http://themeofthecrop.com
* License: GNU General Public License v2.0 or later
* License URI: http://www.gnu.org/licenses/gpl-2.0.html
* Requires at least: 4.0
* Tested up to: 4.01
*
* Text Domain: rtbdomain
* Domain Path: /languages/
*
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU
* General Public License as published by the Free Software Foundation; either version 2 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU General Public License along with this program; if not, write
* to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
if ( ! defined( 'ABSPATH' ) )
exit;
/**
* Remove the party field from the reservation fieldset
*/
if ( !function_exists( 'rtbrpf_remove_party' ) ) {
add_filter( 'rtb_booking_form_fields', 'rtbrpf_remove_party', 10, 2 );
function rtbrpf_remove_party( $fields, $request ) {
$fields['reservation']['fields']['party']['callback'] = '__return_false';
return $fields;
}
} // endif;
/**
* Adjust validation results so the party is not required
*/
if ( !function_exists( 'rtbrpf_allow_empty_party' ) ) {
add_action( 'rtb_validate_booking_submission', 'rtbrpf_allow_empty_party', 100 );
function rtbrpf_allow_empty_party( $booking ) {
// Remove any validation errors attached to the email field
foreach( $booking->validation_errors as $key => $error ) {
if ( $error['field'] == 'party' ) {
unset( $booking->validation_errors[ $key ] );
}
}
}
} // endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment