Advertisement
salvatorifabio

Widget product search

Nov 17th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.24 KB | None | 0 0
  1. <?php
  2. class Custom_WooCommerce_Widget_Product_Search extends WP_Widget {
  3.  
  4. function Custom_WooCommerce_Widget_Product_Search() {
  5.  
  6. /* Widget variable settings. */
  7. $this->woo_widget_cssclass = 'Custom widget_product_search';
  8. $this->woo_widget_description = __( 'Allows customers to search all the products based on checkin & checkout dates.', 'woocommerce-booking' );
  9. $this->woo_widget_idbase = 'woocommerce_booking_availability_search';
  10. $this->woo_widget_name = __( 'WooCommerce Bookings Availability Search', 'woocommerce-booking' );
  11.  
  12. /* Widget settings. */
  13. $widget_ops = array( 'classname' => $this->woo_widget_cssclass, 'description' => $this->woo_widget_description );
  14.  
  15. /* Create the widget. */
  16. $this->WP_Widget('custom_product_search', $this->woo_widget_name, $widget_ops);
  17. }
  18.  
  19. /**
  20. * widget function.
  21. *
  22. * @see WP_Widget
  23. * @access public
  24. * @param array $args
  25. * @param array $instance
  26. * @return void
  27. */
  28. function get_custom_page_url($page_name)
  29. {
  30. global $wpdb;
  31. $page_name_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_name = '".$page_name."' AND post_status = 'publish' AND post_type = 'page' ");
  32. $page_permalink = get_permalink($page_name_id);
  33. return $page_permalink;
  34. }
  35. function widget( $args, $instance ) {
  36. extract($args);
  37.  
  38. $start_date = $instance['start_date_label'];
  39. $end_date = $instance['end_date_label'];
  40. $search_label = $instance['search_label'];
  41. $text_label = $instance['text_label'];
  42. if(isset($instance['title_label']))
  43. {
  44. $title = $instance['title_label'];
  45. }
  46. else
  47. {
  48. $title = '';
  49. }
  50. $title = apply_filters('widget_title', $title, $instance, $this->id_base);
  51. //$title = apply_filters('widget_title', $title, $instance, $this->id_base);
  52.  
  53. echo $before_widget;
  54. if ( $title )
  55. echo $before_title . $title . $after_title;
  56.  
  57. $url = plugins_url();
  58. $action = get_permalink( woocommerce_get_page_id( 'shop' ) );
  59. $calendar_theme = json_decode(get_option('woocommerce_booking_global_settings'));
  60. if (isset($calendar_theme))
  61. {
  62. $calendar_theme_sel = $calendar_theme->booking_themes;
  63. $booking_language = $calendar_theme->booking_language;
  64. $date_format = $calendar_theme->booking_date_format;
  65. }
  66. else
  67. {$calendar_theme_sel = "smoothness";
  68. $booking_language = "en-GB";
  69. $date_format = "yy-mm-dd";
  70. }
  71.  
  72. wp_enqueue_style('jquery-ui',"$url/woocommerce-booking/css/themes/$calendar_theme_sel/jquery-ui.css");
  73. wp_enqueue_script('jquery-ui');
  74. wp_register_script('jquery-ui-datepicker2',"$url/woocommerce-booking/js/i18n/jquery.ui.datepicker-$booking_language.js");
  75. wp_enqueue_script('jquery-ui-datepicker2');
  76. wp_enqueue_script('jquery-ui-datepicker');
  77.  
  78. $abc = <<<HTML
  79. <script type="text/javascript">
  80. jQuery(document).ready(function(){
  81. var today = new Date();
  82. var dd = today.getDate();
  83.  
  84. jQuery( "#w_check_in" ).datepicker({minDate: today,dateFormat:"$date_format",altField: "#w_checkin",altFormat: "yy-mm-dd",onClose: function( selectedDate ) {
  85.  
  86. jQuery("#w_check_out" ).datepicker("option", "minDate", selectedDate);
  87. }});
  88. jQuery("#w_check_out").datepicker({minDate:today,dateFormat:"$date_format",altField: "#w_checkout",altFormat: "yy-mm-dd"});
  89.  
  90.  
  91. jQuery("#w_check_in").datepicker("option",jQuery.datepicker.regional[ "$booking_language" ]);
  92. jQuery("#w_check_out").datepicker("option",jQuery.datepicker.regional[ "$booking_language" ]);
  93.  
  94. jQuery("#ui-datepicker-div").wrap("<div class=\"hasDatepicker\"></div>");
  95. });
  96. </script>
  97. <div id="wrapper" style="width:300px !important;" >
  98. <form role="search" method="get" id="searchform" action="$action">
  99. <table>
  100. <tr>
  101. <td>$start_date&nbsp;</td>
  102. <td><input id="w_check_in" name="w_check_in" style="width:160px" type="text" readonly/><input type="hidden" id="w_checkin" name="w_checkin"></td>
  103. </tr>
  104. <tr>
  105. <td>
  106. $end_date&nbsp
  107. </td>
  108. <td>
  109. <input id="w_check_out" name="w_check_out" style="width:160px" type="text" readonly/><input type="hidden" id="w_checkout" name="w_checkout">
  110. </td>
  111. </tr>
  112. <tr>
  113. <td></td><td><input type="submit" id="search" value="$search_label" /></td>
  114. </tr>
  115. <tr><td></td></tr>
  116. <tr>
  117. <td colspan="2">$text_label</td>
  118. </tr>
  119.  
  120. </table>
  121. </form>
  122. </div>
  123. HTML;
  124. echo $abc;
  125.  
  126. echo $after_widget;
  127. }
  128.  
  129. /**
  130. * update function.
  131. *
  132. * @see WP_Widget->update
  133. * @access public
  134. * @param array $new_instance
  135. * @param array $old_instance
  136. * @return array
  137. */
  138. function update( $new_instance, $old_instance ) {
  139. $instance['start_date_label'] = strip_tags(stripslashes($new_instance['start_date_label']));
  140. $instance['end_date_label'] = strip_tags(stripslashes($new_instance['end_date_label']));
  141. $instance['search_label'] = strip_tags(stripslashes($new_instance['search_label']));
  142. $instance['text_label'] = stripslashes($new_instance['text_label']);
  143. $instance['title_label'] = stripslashes($new_instance['title_label']);
  144. return $instance;
  145. }
  146.  
  147. /**
  148. * form function.
  149. *
  150. * @see WP_Widget->form
  151. * @access public
  152. * @param array $instance
  153. * @return void
  154. */
  155. function form( $instance ) {
  156. global $wpdb;
  157. ?>
  158. <p><label for="<?php echo $this->get_field_id('title_label'); ?>"><?php _e('Title Label:', 'woocommerce-booking' ) ?></label>
  159. <input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id('title_label') ); ?>" name="<?php echo esc_attr( $this->get_field_name('title_label') ); ?>" value="<?php if (isset ( $instance['title_label'])) {echo esc_attr( $instance['title_label'] );} ?>" /></p>
  160.  
  161. <p><label for="<?php echo $this->get_field_id('start_date_label'); ?>"><?php _e('Start Date Label:', 'woocommerce-booking' ) ?></label>
  162. <input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id('start_date_label') ); ?>" name="<?php echo esc_attr( $this->get_field_name('start_date_label') ); ?>" value="<?php if (isset ( $instance['start_date_label'])) {echo esc_attr( $instance['start_date_label'] );} ?>" /></p>
  163. <p><label for="<?php echo $this->get_field_id('end_date_label'); ?>"><?php _e('End Date Label:', 'woocommerce-booking' ) ?></label>
  164. <input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id('end_date_label') ); ?>" name="<?php echo esc_attr( $this->get_field_name('end_date_label') ); ?>" value="<?php if (isset ( $instance['end_date_label'])) {echo esc_attr( $instance['end_date_label'] );} ?>" /></p>
  165. <p><label for="<?php echo $this->get_field_id('search_label'); ?>"><?php _e('Search Button Label:', 'woocommerce-booking' ) ?></label>
  166. <input type="text" class="widefat" id="<?php echo esc_attr( $this->get_field_id('search_label') ); ?>" name="<?php echo esc_attr( $this->get_field_name('search_label') ); ?>" value="<?php if (isset ( $instance['search_label'])) {echo esc_attr( $instance['search_label'] );} ?>" /></p>
  167. <p><label for="<?php echo $this->get_field_id('text_label'); ?>"><?php _e('Text (appears below Search button)', 'woocommerce-booking' ) ?></label>
  168. <textarea class="widefat" id="<?php echo esc_attr( $this->get_field_id('text_label') ); ?>" name="<?php echo esc_attr( $this->get_field_name('text_label') ); ?>"><?php if (isset ( $instance['text_label'])) {echo esc_attr( $instance['text_label'] );} ?></textarea></p>
  169. <?php
  170. }
  171.  
  172. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement