• Resolved carcayu80

    (@carcayu80)


    Let’s I have a tour that have dates every tuesday PLUS two unique special dates, one in first friday of may and the second last sunday of the year.

    How can I define this using calendar limits? I mean: the only way I found is selecting all tuesdays, fridays and sundays and then manually adding exceptions for all fridays and sundays except two.

    Id there any way to do It more simple? I mean, as there is an option to exclude specific dates, wouldnt be it interesting to have the option to include specific dates?

    Thanks in advance.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Patrick – WPMU DEV Support

    (@wpmudevsupport12)

    Hi @carcayu80

    I hope you are doing well.

    I am afraid it may require some coding, before we ping our developers to verify if there is any workaround let me verify if we are on the same page.

    Your calendar will show up as available dates, Tuesdays and then the first Friday of May and the second last Sunday of the year, all other dates will be unavailable correct?

    Best Regads
    Patrick Freitas

    Thread Starter carcayu80

    (@carcayu80)

    Correct. And It can be only done now selecting tuesdays, fridays and sundays as available weekdays and then manually blocking a lot of days for frdays and sundays

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @carcayu80

    Thank you for confirmation!

    At the moment – you are right, the only way would be to select Tuesdays, Fridays and Sundays as available days and then add exception dates manually. That would work well, I believe, for a year or two (if these are only two days over a years) but if you want that to be “infinite” then automating it would be better.

    I’m not sure, though, if that’d be easy to achieve. It would require custom code and finding out the “first Friday of May” and “2nd last Sunday” of a year for each year isn’t very difficult with PHP too but then this needs to be applied to datepicker and what I’m not sure is – if we can use any existing filter hook for this or if it requires changes in plugin code.

    I have asked our developers about it and we’ll update you here once we got response.

    Note please: our developers are dealing with a lot of complex tasks on daily basis so their response time might be a bit longer than ours. But we’ll let you know here.

    Best regards,
    Adam

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @carcayu80,

    Could you please try the following snippet and then check whether it helps?

    <?php
    
    add_action( 'forminator_before_form_render', 'wpmudev_disable_specific_dates', 10, 5 );
    function wpmudev_disable_specific_dates( $id, $form_type, $post_id, $form_fields, $form_settings ){
    	if( $id != 361 ){
    		return;
    	}
    
    	$update = false;
    	$form_meta = get_post_meta($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' ){
    					
    					$timestamp = strtotime(date('Y')."-05-00 first friday");
    					$first_friday = date("m/d/Y", $timestamp);
    
    					$second_timestamp = strtotime(date('Y', strtotime('+1 year'))."-01-00 first sunday -14 days");
    					$second_last_sunday = date("m/d/Y", $second_timestamp);
    
    					if( is_array( $form_meta['fields'][$form_key]['disabled-dates'] ) ) {
    						if( in_array( $first_friday, $form_meta['fields'][$form_key]['disabled-dates'] ) ) {
    							return;
    						}
    
    						if( in_array( $second_last_sunday, $form_meta['fields'][$form_key]['disabled-dates'] ) ) {
    							return;
    						}
    					}
    
    					if( $first_friday ){
    						$form_meta['fields'][$form_key]['disabled-dates'][] = $first_friday;
    						$update = true;
    					}
    					
    					if( $second_last_sunday ){
    						$form_meta['fields'][$form_key]['disabled-dates'][] = $second_last_sunday;
    						$update = true;
    					}
    				}
    			}
    		}
    
    		if( $update ) {
    			update_post_meta($id, 'forminator_form_meta', $form_meta);
    		}
    
    	}
    	add_filter( 'forminator_field_date_markup', 'wpmudev_disabled_dates_specified', 10, 3 );
    }
    
    function wpmudev_disabled_dates_specified( $html, $field, $cls ) {
    	if( $field['element_id'] == 'date-1' ){
    		$disabled_dates = array();
    		$timestamp = strtotime(date('Y')."-05-00 first friday");
    		$first_friday = date("m/d/Y", $timestamp);
    
    		$second_timestamp = strtotime(date('Y', strtotime('+1 year'))."-01-00 first sunday -14 days");
    		$second_last_sunday = date("m/d/Y", $second_timestamp);
    		$disabled_dates[] = $first_friday;
    		$disabled_dates[] = $second_last_sunday;
    		$disabled_date = implode( ',', $disabled_dates );
    		if( strpos( $html, 'data-disable-date=""') !== false ){
    			$html = str_replace('data-disable-date=""', "data-disable-date=$disabled_date", $html);
    		}
    	}
    	return $html;
    }

    In the above code you’ll need no update the number 361 in the following line:
    if( $id != 361 ){

    To your form ID, suppose your form ID is 123, then the above line will change to:
    if( $id != 123 ){

    You can implement the above code as a mu-plugins. Please check this link on how to implement the above code as a mu-plugins:
    https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#installing-mu-plugins

    Once the above code is applied, it should update the “Disabled Dates” in the “Datepicker” field.

    Kind Regards,
    Nithin

    Plugin Support Amin – WPMU DEV Support

    (@wpmudev-support2)

    Hello @carcayu80 ,

    We haven’t heard from you for several days now, so it looks like the above code snippet worked for you.

    Feel free to re-open this ticket if needed.

    Kind regards
    Kasia

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Adding unique dates’ is closed to new replies.