• Resolved rossanderson

    (@rossanderson)


    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.

Viewing 15 replies - 1 through 15 (of 37 total)
  • Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @rossanderson

    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,
    Kris

    Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @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 John

    Thread Starter rossanderson

    (@rossanderson)

    Can 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

    Thread Starter rossanderson

    (@rossanderson)

    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

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @rossanderson

    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,
    Adam

    Thread Starter rossanderson

    (@rossanderson)

    I 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.

    Thread Starter rossanderson

    (@rossanderson)

    Thread Starter rossanderson

    (@rossanderson)

    I also uploaded a document with the short code of the form to same one drive folder

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    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,
    Kasia

    Thread Starter rossanderson

    (@rossanderson)

    Thank 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.

    Thread Starter rossanderson

    (@rossanderson)

    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

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @rossanderson

    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 Freitas

    Thread Starter rossanderson

    (@rossanderson)

    Is 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?

    Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @rossanderson

    We pinged our developers to verify if this is possible, we will keep you posted.

    Best Regards
    Patrick Freitas

    Plugin Support Dimitris – WPMU DEV Support

    (@wpmudev-support6)

    Hello @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/VeUCaMCRw6ryWEmdihP2LBvqIdF5Rr

    Warm regards,
    Dimitris

Viewing 15 replies - 1 through 15 (of 37 total)
  • The topic ‘Only allow one customer to book a day’ is closed to new replies.