/includes/wc-predictive-template-functions.php

  1. <?php 
  2. if ( ! defined( 'ABSPATH' ) ) { 
  3. exit; // Exit if accessed directly 
  4.  
  5. /** 
  6. * Get templates passing attributes and including the file. 
  7. * 
  8. * @access public 
  9. * @param string $template_name 
  10. * @param array $args (default: array()) 
  11. * @return void 
  12. */ 
  13. function wc_ps_get_template( $template_name, $args = array() ) { 
  14. if ( $args && is_array( $args ) ) { 
  15. extract( $args ); 
  16.  
  17. $template_file_path = wc_ps_get_template_file_path( $template_name ); 
  18.  
  19. if ( ! file_exists( $template_file_path ) ) { 
  20. _doing_it_wrong( __FUNCTION__, sprintf( '<code>%s</code> does not exist.', $template_file_path ), '1.0.0' ); 
  21. return; 
  22.  
  23. // Allow 3rd party plugin filter template file from their plugin 
  24. $template_file_path = apply_filters( 'wc_ps_get_template', $template_file_path, $template_name, $args ); 
  25.  
  26. do_action( 'wc_ps_before_template_part', $template_name, $template_file_path, $args ); 
  27.  
  28. include( $template_file_path ); 
  29.  
  30. do_action( 'wc_ps_after_template_part', $template_name, $template_file_path, $args ); 
  31.  
  32. /** 
  33. * wc_ps_get_template_file_path( $file ) 
  34. * 
  35. * This is the load order: 
  36. * 
  37. * yourtheme / woocommerce / $file 
  38. * yourtheme / $file 
  39. * WOOPS_TEMPLATE_PATH / $file 
  40. * 
  41. * @access public 
  42. * @param $file string filename 
  43. * @return PATH to the file 
  44. */ 
  45. function wc_ps_get_template_file_path( $file = '' ) { 
  46. // If we're not looking for a file, do not proceed 
  47. if ( empty( $file ) ) 
  48. return; 
  49.  
  50. // Look for file in stylesheet 
  51. if ( file_exists( get_stylesheet_directory() . '/woocommerce/' . $file ) ) { 
  52. $file_path = get_stylesheet_directory() . '/woocommerce/' . $file; 
  53.  
  54. // Look for file in stylesheet 
  55. } elseif ( file_exists( get_stylesheet_directory() . '/' . $file ) ) { 
  56. $file_path = get_stylesheet_directory() . '/' . $file; 
  57.  
  58. // Look for file in template 
  59. } elseif ( file_exists( get_template_directory() . '/woocommerce/' . $file ) ) { 
  60. $file_path = get_template_directory() . '/woocommerce/' . $file; 
  61.  
  62. // Look for file in template 
  63. } elseif ( file_exists( get_template_directory() . '/' . $file ) ) { 
  64. $file_path = get_template_directory() . '/' . $file; 
  65.  
  66. // Get default template 
  67. } else { 
  68. $file_path = WOOPS_TEMPLATE_PATH . '/' . $file; 
  69.  
  70. // Return filtered result 
  71. return apply_filters( 'wc_ps_get_template_file_path', $file_path, $file ); 
  72.  
  73. /** 
  74. * wc_ps_search_form() 
  75. * 
  76. * @return void 
  77. */ 
  78. function wc_ps_search_form( $ps_id = '', $template = 'sidebar', $args = array(), $echo = false ) { 
  79.  
  80. $ps_id = str_replace( 'products_predictive_search-', '', $ps_id ); 
  81. if ( empty( $ps_id ) ) { 
  82. $ps_id = rand( 100, 10000 ); 
  83.  
  84. ob_start(); 
  85.  
  86. // Custom Style for Individual Predictive Search Widget 
  87. $custom_style = ''; 
  88. if ( isset( $args['show_image'] ) && 0 == $args['show_image'] ) { 
  89. $custom_style .= ' 
  90. .ac_results_' . $ps_id . ' .rs_avatar { 
  91. display: none !important; 
  92. .predictive_results.ac_results_' . $ps_id . ' .rs_content_popup { 
  93. width: 100% !important; 
  94. }'; 
  95. if ( isset( $args['show_desc'] ) && 0 == $args['show_desc'] ) { 
  96. $custom_style .= ' 
  97. .ac_results_' . $ps_id . ' .rs_description { 
  98. display: none !important; 
  99. }'; 
  100.  
  101. if ( '' != trim( $custom_style ) ) { 
  102. echo '<style>' . $custom_style . '</style>'; 
  103.  
  104. if ( 'header' == $template ) { 
  105. wc_ps_search_form_header_tpl( $ps_id, $args ); 
  106. } else { 
  107. wc_ps_search_form_sidebar_tpl( $ps_id, $args ); 
  108.  
  109. $search_form = ob_get_clean(); 
  110.  
  111. if ( $echo ) { 
  112. echo $search_form; 
  113. } else { 
  114. return $search_form; 
  115.  
  116. /** 
  117. * wc_ps_search_form_sidebar_tpl() 
  118. * 
  119. * @return void 
  120. */ 
  121. function wc_ps_search_form_sidebar_tpl( $ps_id, $args = array() ) { 
  122. global $wc_predictive_search_sidebar_template_settings; 
  123.  
  124. if ( ! is_array( $args ) ) { 
  125. $args = array(); 
  126.  
  127. $args['popup_wide'] = $wc_predictive_search_sidebar_template_settings['popup_wide']; 
  128. $args['cat_align'] = $wc_predictive_search_sidebar_template_settings['sidebar_category_dropdown_align']; 
  129. $args['cat_max_wide'] = $wc_predictive_search_sidebar_template_settings['sidebar_category_dropdown_max_wide']; 
  130.  
  131. wc_ps_get_template( 'search-bar/predictive-search-form-sidebar.php',  
  132. apply_filters( 'wc_ps_search_form_sidebar_tpl_args', array( 
  133. 'ps_id' => $ps_id,  
  134. 'ps_widget_template' => 'sidebar',  
  135. 'ps_args' => $args 
  136. ) ) 
  137. ); 
  138.  
  139. /** 
  140. * wc_ps_search_form_header_tpl() 
  141. * 
  142. * @return void 
  143. */ 
  144. function wc_ps_search_form_header_tpl( $ps_id, $args = array() ) { 
  145. global $wc_predictive_search_header_template_settings; 
  146.  
  147. if ( ! is_array( $args ) ) { 
  148. $args = array(); 
  149.  
  150. $args['popup_wide'] = $wc_predictive_search_header_template_settings['popup_wide']; 
  151. $args['cat_align'] = $wc_predictive_search_header_template_settings['header_category_dropdown_align']; 
  152. $args['cat_max_wide'] = $wc_predictive_search_header_template_settings['header_category_dropdown_max_wide']; 
  153.  
  154. wc_ps_get_template( 'search-bar/predictive-search-form-header.php',  
  155. apply_filters( 'wc_ps_search_form_header_tpl_args', array( 
  156. 'ps_id' => $ps_id,  
  157. 'ps_widget_template' => 'header',  
  158. 'ps_args' => $args 
  159. ) ) 
  160. ); 
  161.  
  162. /** 
  163. * wc_ps_get_popup_item_tpl() 
  164. * 
  165. * @return void 
  166. */ 
  167. function wc_ps_get_popup_item_tpl() { 
  168.  
  169. wc_ps_get_template( 'popup/item.php',  
  170. apply_filters( 'wc_ps_popup_item_tpl_args', array() ) 
  171. ); 
  172.  
  173. /** 
  174. * wc_ps_get_popup_footer_sidebar_tpl() 
  175. * 
  176. * @return void 
  177. */ 
  178. function wc_ps_get_popup_footer_sidebar_tpl() { 
  179. global $wc_predictive_search_sidebar_template_settings; 
  180.  
  181. wc_ps_get_template( 'popup/footer-sidebar.php',  
  182. apply_filters( 'wc_ps_popup_footer_sidebar_tpl_args', array( 
  183. 'popup_seemore_text' => $wc_predictive_search_sidebar_template_settings['sidebar_popup_seemore_text'] 
  184. ) ) 
  185. ); 
  186.  
  187. /** 
  188. * wc_ps_get_popup_footer_header_tpl() 
  189. * 
  190. * @return void 
  191. */ 
  192. function wc_ps_get_popup_footer_header_tpl() { 
  193.  
  194. wc_ps_get_template( 'popup/footer-header.php',  
  195. apply_filters( 'wc_ps_popup_footer_header_tpl_args', array( 
  196. 'popup_seemore_text' => '' 
  197. ) ) 
  198. ); 
  199.  
  200. /** 
  201. * wc_ps_get_results_item_tpl() 
  202. * 
  203. * @return void 
  204. */ 
  205. function wc_ps_get_results_item_tpl() { 
  206. wc_ps_get_template( 'results-page/item.php',  
  207. apply_filters( 'wc_ps_results_item_tpl_args', array() ) 
  208. ); 
  209.  
  210. /** 
  211. * wc_ps_get_results_header_tpl() 
  212. * 
  213. * @return void 
  214. */ 
  215. function wc_ps_get_results_header_tpl( $args = array() ) { 
  216. if ( ! is_array( $args ) ) { 
  217. $args = array(); 
  218.  
  219. wc_ps_get_template( 'results-page/header.php',  
  220. apply_filters( 'wc_ps_results_header_tpl_args', $args ) 
  221. ); 
  222.  
  223. /** 
  224. * wc_ps_get_results_footer_tpl() 
  225. * 
  226. * @return void 
  227. */ 
  228. function wc_ps_get_results_footer_tpl() { 
  229. wc_ps_get_template( 'results-page/footer.php',  
  230. apply_filters( 'wc_ps_results_footer_tpl_args', array() ) 
  231. ); 
  232.  
  233. function wc_ps_get_product_categories() { 
  234. global $wc_predictive_search_cache; 
  235. $categories_list = false; 
  236. $append_transient_name = ''; 
  237.  
  238. if ( $wc_predictive_search_cache->enable_cat_cache() ) { 
  239. if ( class_exists('SitePress') ) { 
  240. $current_lang = apply_filters( 'wpml_current_language', NULL ); 
  241. $append_transient_name = $current_lang; 
  242.  
  243. $categories_list = $wc_predictive_search_cache->get_product_categories_dropdown_cache( $append_transient_name ); 
  244.  
  245. if ( false === $categories_list ) { 
  246. $language = trim( $append_transient_name ); 
  247. if ( '' != $language ) { 
  248. $language = '_' . $language; 
  249. update_option( 'predictive_search_have_cat_cache' . $language, 'no' ); 
  250.  
  251. return $categories_list; 
  252.  
  253. ?> 
.