• Resolved joshuachaw

    (@joshuachaw)


    Hi,

    I understand that Restaurant Reservation does not sync the opening hours of different locations from Business Profile on the booking time selection.

    The way I hope to overcome is when a location is selected from the multi-location drop down of Restaurant Reservation, I want to execute a short code supplying the location ID of the location selected to display the opening hours of that location in brief format.
    <?php /*echo do_shortcode("[contact-card location=\"65\"]"); */?>

    This is so that the guest is aware of the opening hours before entering the booking details follows.

    Could you advice what is a good way of achieving the above ?

    Thank you.

    The page I need help with: [log in to see the link]

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter joshuachaw

    (@joshuachaw)

    Hi,

    I managed to get it working using ajax, calling to bpwfwp_print_contact_card providing the parameter location.

    However the value of rtb-location from the location drop down is Term_ID from taxonomy table, the location id parameter required by bpwfwp_print_contact_card is Post_ID.

    How do I map between the 2 ? is it matching PostName from POST table against Slug from TERM table ?
    i.e use rtb-location as term_id to find the corresponding slug, look up matching slug as post name from POST table and the post_id is the location_id to bpwfwp_print_contact_card.

    Is that correct way of mapping rtb-location value to location_id ?

    Regards,
    Josh

    Thread Starter joshuachaw

    (@joshuachaw)

    Ok I got it sorted out with WP_Query. Thanks. Now it;s working perfectly as what I wanted.

    Thread Starter joshuachaw

    (@joshuachaw)

    For anyone what is interested :

      Child Theme functions.php
    <?php
    add_action( 'wp_enqueue_scripts', 'my_theme_enqueue_styles' );
    function my_theme_enqueue_styles() {
        wp_enqueue_style( 'parent-style', get_template_directory_uri() . '/style.css' );
    }
    
    //Register Opening Hours Ajax
    wp_enqueue_script( 'rtb-mylocation-js', get_stylesheet_directory_uri() . '/assets/js/opening-hours.js', array( 'jquery' ), '', true );
    wp_localize_script( 'rtb-mylocation-js', 'location_ajax_script', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
    add_action( 'wp_ajax_the_ajax_hook', 'location_action_function' );
    add_action( 'wp_ajax_nopriv_the_ajax_hook', 'location_action_function' );
    
    function location_action_function(){
     $args = array(
        'post_type' => array('location'),
    	'post_status' => array('publish'),
        'meta_query' => array(
            array(
                'key' => 'rtb_location',
                'value' => $_POST['rtb-location']
            )
        )
      );
    
     $query = new WP_Query($args);
    
     if ($query->have_posts()) {
            $query->the_post();
            $location_id = get_the_ID();
    }	
    
     $openinghours = '';
    
     if ( function_exists( 'bpwfwp_print_contact_card' ) ) 
        {
           $openinghours = bpwfwp_print_contact_card(
    			array(
    				'show_name'	=> true,
                                    'show_address'  => false,
                                    'show_get_directions'  => false,
    				'show_phone'	=> false,
    				'show_contact'	=> false,
    				'show_opening_hours' => true,
    				'show_opening_hours_brief' => true,
    				'show_map' => false,
                    'location' => $location_id,
    			)
    		);
        }
     echo $openinghours;  // this is passed back to the javascript function
     die();
     }
    ?>
      opening-hours.js
    jQuery(document).ready(function ($) {
    	$('#rtb-location').change(function(){
    	   $('#opening-hours').remove();	
    	   
    	    var location_id = $(this).val();
    	    if ($(this).val()==='') { alert('Please select a location'); return false;}
    	    jQuery.post(location_ajax_script.ajaxurl, { 'action': 'the_ajax_hook', 'rtb-location': location_id } ,
    
     function(response_from_the_action_function){
    		$('.location').append('<div id="opening-hours">' + response_from_the_action_function + '</div>');  
            });
    	});
      });
    Plugin Support jaysupport

    (@jaysupport)

    Hi Joschua,

    Wow, you got that figured out before we had a chance to get back to you after the weekend. Good stuff! And thank you for sharing your workaround, which may help someone else looking to get a similar functionality.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Mutliple Location Opening Hours’ is closed to new replies.