Only allow one customer to book a day
-
I was wondering if you can limit the amount of bookings within a day. For example if a customer books a car detail in the morning and a another customer goes to the website about 20 minutes after the original customer booked for that day is there anyway to show that new customer they will have to book the next available day so you would only take one booking a day.
-
I hope you are doing good today.
I pinged our SLS Team so that they can double-check what will be possible for you. We will post an update here as soon as more information is available.
Kind Regards,
KrisHi @rossanderson,
Please check if the following workaround helps.
add_filter( 'forminator_custom_form_submit_errors', function( $submit_errors, $form_id, $field_data_array ) { if( $form_id != 361 ) { return $submit_errors; } $last_entry = ''; // Change this to the message that you want to show. $message = 'Booking has been done for the day. Please book for another day.'; foreach( $field_data_array as $key => $value ){ if( $value['name'] == 'date-1' ){ if( $value['value'] != '' ){ $last_entry = wpmudev_get_last_entry_by_date( $form_id, $value['value'] ); } } } if ( ! empty( $last_entry ) ) { $submit_errors[]['submit'] = $message; } return $submit_errors; },15,3); add_filter( 'forminator_custom_form_invalid_form_message', 'wpmudev_invalid_form_error', 10, 2 ); function wpmudev_invalid_form_error( $invalid_form_message, $form_id ){ if( $form_id != 361 ) { return $invalid_form_message; } $last_entry = ''; if( isset( $_POST ) ){ $date = isset( $_POST['date-1'] ) ? sanitize_text_field( $_POST['date-1'] ) : ''; if( $date ){ $last_entry = wpmudev_get_last_entry_by_date( $form_id, $date ); } } if ( ! empty( $last_entry ) ) { $invalid_form_message = __( 'Booking has been done for the day. Please book for another day.', 'forminator' ); } return $invalid_form_message; } function wpmudev_get_last_entry_by_date( $form_id, $date ){ global $wpdb; $table_name = Forminator_Database_Tables::get_table_name( Forminator_Database_Tables::FORM_ENTRY_META ); $entry_table_name = Forminator_Database_Tables::get_table_name( Forminator_Database_Tables::FORM_ENTRY ); $sql = "SELECT m.<code>entry_id</code> FROM {$table_name} m LEFT JOIN {$entry_table_name} e ON(e.<code>entry_id</code> = m.<code>entry_id</code>) WHERE e.<code>form_id</code> = %d AND m.<code>meta_key</code> = %s AND m.<code>meta_value</code> = %s order by m.<code>meta_id</code>"; $entry_id = $wpdb->get_var( $wpdb->prepare( $sql, $form_id, 'date-1', $date ) ); if ( $entry_id ) { return $entry_id; } return false; }
Assuming that you have a date field date-1, in the code, we check if an entry exists with the same date, then an error message will appear. Please note that you need to change the form ID from 361 to your form’s ID, and if the date field’s ID is different, that too has to be changed.
You can add the code using a mu-plugin. Please find more details about how to add a mu-plugin in our documentation here: https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins
Kind Regards,
Nebu JohnCan you please tell me how I can download the plug-in can you send me the link to download the file. Can you also please tell me the steps how I can insert this code to the website
Is there anyway I can get a video of how this is done and how to insert the code to the website to limit the date picker to one appointment a day. I am just a little confused on how I can enter this code to the website.
Thank you
There’s no need to download any new plugin, my colleague only linked to information about MU (Must Use) type of plugins so let me instead give you a step-by-step guide on how to add the code to the site.
If you have cPanel access, the simplest way is to:
– open cPanel and use its “File Manager” tool
– navigate to the “/wp-content/” folder inside your site’s WP installation folder
– see if there already is a folder named “mu-plugins” inside or not; if not, create it; the path would be “/wp-content/mu-plugins”– enter that /wp-content/mu-plugins folder and create empty file with a .php extension there (e.g. “forminator-datepicker-limit.php”) and open it for editing using “code editor” option
– copy the code from my colleague’s post above and paste it into that file
– in other browser tab login to your site and go to edit form in question
– find out what’s the ID of your datepicker and if it’s different than date-1 then replace all occurrences of date-1 in the code with that ID (e.g. date-2 or date-3, depending on how it is on your form)– replace all the occurrences of number 361 in the code with the numerical ID of your form (you can see it in form shortcode and/or in browser address bar when editing the form)
– finally, save the file
That’s it. It should work out of the box, though you may need to clear all cache on site/server first.
Best regards,
AdamI followed the instructions and cleared the cache on the server side after I was done saving the file I went back to my website to clear the cash using the light speed plug-in after that I went to my form and an error message popped up on the top of the screen. Clicked on the update button to update the form but an error message popped up and said and some thing occurred and the format couldn’t be saved. I am going to share a OneDrive link that includes the code file that I edited to show the ID of the form. A picture of the error message that is appearing in WordPress. And the ID of the date picker.
OneDrive link to images
I also uploaded a document with the short code of the form to same one drive folder
Hello @rossanderson ,
There is
<?php
tag missing at the start of the forminator-datepicker.php file. You need to add it at the beginning of the file and errors will disappear.kind regards,
KasiaThank you once the customer books the appointment for that day I know the form will not be allowed to take another booking for that day but will the day that has the booking be grayed out on the calendar. If not is there anyway to have the day where a customer already booked for that given day to be graded out. Instead of just showing the next client an error message if they try to book that day where a customer is already booked.
Are you talking about the name of the file if so should I put the tag in front of the title. I just renamed it and it gave me the same error message. Example of the file name.
<?phpforminator-datepicker-limit.php
It is on the code itself the file name can keep forminator-datepicker-limit.php, but I found the problem, when we copied the code to the WordPress forum it replaced a part of the code and it caused the issue.
I uploaded the code here, https://gist.github.com/patrickfreitasdev/8b82ae877640f2e2796cd2d5b332ca83
It is already include the <?php too.
Please, remove the old code and use this version instead, the same steps about form ID need to be followed:
Assuming that you have a date field date-1, in the code, we check if an entry exists with the same date, then an error message will appear. Please note that you need to change the form ID from 361 to your form’s ID, and if the date field’s ID is different, that too has to be changed.
Best Regards
Patrick FreitasIs there a way to grey out the day on the calendar that already has a booking. This way it would give the client a visual representation that that specific day is already booked instead of just showing the client an error message?
We pinged our developers to verify if this is possible, we will keep you posted.
Best Regards
Patrick FreitasHello @rossanderson
Please add the following code at the end of the same mu-plugin suggested before:
add_action( 'forminator_form_after_save_entry', 'wpmudev_disable_booking_dates', 10, 2 ); add_action( 'forminator_form_after_handle_submit', 'wpmudev_disable_booking_dates', 10, 2 ); function wpmudev_disable_booking_dates( $module_id, $response ){ if( $module_id != 361 ){ return; } $form_meta = get_post_meta($module_id, 'forminator_form_meta', true); if( $form_meta ){ if( isset( $form_meta['fields'] ) ){ foreach( $form_meta['fields'] as $form_key => $form_val ){ if( $form_val['id'] == 'date-1' ){ if( isset( $_POST ) ){ $date = isset( $_POST['date-1'] ) ? sanitize_text_field( $_POST['date-1'] ) : ''; if( $date ){ $form_meta['fields'][$form_key]['disabled-dates'][] = $date; } } } } } update_post_meta($module_id, 'forminator_form_meta', $form_meta); } }
In that code you will have to replace “361” with your form ID, similar to the previous code. Also, you should use Page Reload instead of Ajax for the form submission method.
All the disabled dates will appear on the date field settings as shown below:
https://monosnap.com/file/VeUCaMCRw6ryWEmdihP2LBvqIdF5RrWarm regards,
Dimitris
- The topic ‘Only allow one customer to book a day’ is closed to new replies.