automatically setting the reservation widget to the correct property when landing...
authorAnthony Talarico <talarico@gaslightmedia.com>
Mon, 13 Aug 2018 19:29:28 +0000 (15:29 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Mon, 13 Aug 2018 19:29:28 +0000 (15:29 -0400)
functions.php
parts/reservation-form-main.php

index 16199db..2016f2d 100644 (file)
@@ -137,7 +137,30 @@ function mytheme_search_loop() {
 
   <?php endwhile;
 }
+function is_tree( $pid ) {
+    global $post;
 
+    if ( is_page($pid) )
+        return true;
+
+    $anc = get_post_ancestors( $post->ID );
+    foreach ( $anc as $ancestor ) {
+        if( is_page() && $ancestor == $pid ) {
+            return true;
+        }
+    }
+    return false;
+}
+function setReservationWidgetProperty($page_id, $props_array){
+    $post = get_post($page_id);
+    $property_name = '';
+    foreach($props_array as $id=>$property){
+        if( is_page($id) || $id == $post->post_parent || is_tree($id) ){
+            $property_name =  $property;
+        } 
+    }
+    return $property_name;
+}
 add_action('thematic_searchloop', 'mytheme_search_loop');
 // End of the Contextual/Highlight Search functions
 add_image_size('glm_blocks', '257', '257', true);
index 9cefd48..0ca5709 100644 (file)
@@ -4,11 +4,28 @@
                     <form method="post">
                         <div class="row resDropdown">
                             <div class="small-12 res-search columns resInput">
+                                <?php 
+                                global $post; 
+                                $properties = array(
+                                    187 => "Stafford's Bay View Inn",
+                                    188 => "Stafford's Crooked River Lodge",
+                                    189 => "Stafford's Perry Hotel"
+                                ); ?>
+                                <?php $ancestorProperty = setReservationWidgetProperty( $post->ID, $properties ); ?>
                                 <select id="propertyName" name="s">
                                      <option value="" selected disabled>Property</option>
-                                      <option value="Stafford's Bay View Inn">Bay View Inn</option>
-                                      <option value="Stafford's Crooked River Lodge">Crooked River Lodge</option>
-                                      <option value="Stafford's Perry Hotel">Perry Hotel</option>
+                                    <?php foreach($properties as $id=>$property){ 
+                                        $short_name = str_replace("Stafford's", "", $property);
+                                        if( $ancestorProperty == $property){ ?>
+                                            <option value="<?php echo $property; ?>" selected><?php echo $short_name; ?></option>
+                                        <?php } else { ?>
+                                            <option value="<?php echo $property ;?>"><?php echo $short_name; ?></option>
+                                        <?php }  ?>
+                                    <?php } ?>
+                                      <!-- <option value="Stafford's Bay View Inn" >Bay View Inn</option>
+                                      <option value="Stafford's Crooked River Lodge" >Crooked River Lodge</option>
+                                      <option value="Stafford's Perry Hotel" >Perry Hotel</option> -->
+
                                 </select>
                             </div>
                             <div class="small-12 res-date columns resInput">