/includes/templates/standard_template/standard_template.php

  1. <?php 
  2. /** 
  3. * Original Template Bulk Order Form Pro 
  4. */ 
  5. ?> 
  6. <?php 
  7. class WCBulkOrderForm_Standard_Template { 
  8. private static $add_script; 
  9. /** 
  10. * Construct. 
  11. */ 
  12. public function __construct() { 
  13. $this->includes(); 
  14. $this->options = get_option('wcbulkorderform_standard_template'); 
  15. //print_r($this->options); 
  16. if(empty($this->options)) { 
  17. register_activation_hook( __FILE__, array( 'WCBulkOrderForm_Settings_Standard_Template', 'default_settings' ) ); 
  18. $this->options = get_option('wcbulkorderform_standard_template'); 
  19. $standard_template_settings = new WCBulkOrderForm_Settings_Standard_Template(); 
  20.  
  21. add_shortcode('wcbulkorder', array( &$this, 'wc_bulk_order_form' ) ); 
  22.  
  23. // Functions to deal with the AJAX request - one for logged in users, the other for non-logged in users. 
  24. add_action( 'wp_ajax_bulk_order_product_search', array( &$this, 'bulk_order_product_search' )); 
  25. add_action( 'wp_ajax_nopriv_bulk_order_product_search', array( &$this, 'bulk_order_product_search' )); 
  26. add_action( 'wp_print_styles', array( &$this, 'load_styles' ), 0 ); 
  27. add_action( 'wp', array($this, 'process_bulk_order_form') ); 
  28. add_action('init', array( &$this, 'register_script')); 
  29. add_action('wp_footer', array( &$this, 'print_script')); 
  30.  
  31. /** 
  32. * Load additional classes and functions 
  33. */ 
  34. public function includes() { 
  35. include_once( 'standard_template_options.php' ); 
  36.  
  37. /** 
  38. * Load CSS 
  39. */ 
  40. public function load_styles() { 
  41.  
  42. if (empty($this->options['no_load_css'])) { 
  43. $autocomplete = file_exists( get_stylesheet_directory() . '/jquery-ui.css' ) 
  44. ? get_stylesheet_directory_uri() . '/jquery-ui.css' 
  45. : plugins_url( '/css/jquery-ui.css', __FILE__ ); 
  46. wp_register_style( 'wcbulkorder-jquery-ui', $autocomplete, array(), '', 'all' ); 
  47.  
  48. $css = file_exists( get_stylesheet_directory() . '/wcbulkorderform.css' ) 
  49. ? get_stylesheet_directory_uri() . '/wcbulkorderform.css' 
  50. : plugins_url( '/css/wcbulkorderform.css', __FILE__ ); 
  51.  
  52. wp_register_style( 'wcbulkorderform', $css, array(), '', 'all' ); 
  53. /** 
  54. * Load JS 
  55. */  
  56. static function register_script() { 
  57. $options = get_option('wcbulkorderform_standard_template'); 
  58. wp_register_script('wcbulkorder_acsearch', plugins_url( '/js/wcbulkorder_acsearch.js' , __FILE__ ), array('jquery', 'jquery-ui-autocomplete'), null, true); 
  59. $display_images = isset($options['display_images']) ? $options['display_images'] : ''; 
  60. $noproductsfound = __( 'No Products Were Found', 'wcbulkorderform' ); 
  61. $variation_noproductsfound = __( 'No Variations', 'wcbulkorderform' ); 
  62. $selectaproduct = __( 'Please Select a Product', 'wcbulkorderform' ); 
  63. $enterquantity = __( 'Enter Quantity', 'wcbulkorderform' ); 
  64. $decimal_sep = wp_specialchars_decode( stripslashes( get_option( 'woocommerce_price_decimal_sep' ) ), ENT_QUOTES ); 
  65. $thousands_sep = wp_specialchars_decode( stripslashes( get_option( 'woocommerce_price_thousand_sep' ) ), ENT_QUOTES ); 
  66. $num_decimals = absint( get_option( 'woocommerce_price_num_decimals' ) ); 
  67. $minLength = 2; 
  68. $Delay = 500; 
  69. wp_localize_script( 'wcbulkorder_acsearch', 'WCBulkOrder', array('url' => admin_url( 'admin-ajax.php' ), 'search_products_nonce' => wp_create_nonce('wcbulkorder-search-products'), 'display_images' => $display_images, 'noproductsfound' => $noproductsfound, 'selectaproduct' => $selectaproduct, 'enterquantity' => $enterquantity, 'variation_noproductsfound' => $variation_noproductsfound, 'variation_noproductsfound' => $variation_noproductsfound, 'decimal_sep' => $decimal_sep, 'thousands_sep' => $thousands_sep, 'num_decimals' => $num_decimals, 'Delay' => $Delay, 'minLength' => $minLength )); 
  70. static function print_script() { 
  71. if ( ! self::$add_script ) 
  72. return; 
  73. wp_print_scripts('wcbulkorder_acsearch'); 
  74. wp_enqueue_style( 'wcbulkorder-jquery-ui' ); 
  75. wp_enqueue_style( 'wcbulkorderform' ); 
  76.  
  77. function process_bulk_order_form() { 
  78. if(isset($_POST['wcbulkorderproduct'])) { 
  79. global $woocommerce; 
  80. $prod_name = $_POST['wcbulkorderproduct']; 
  81. $prod_quantity = $_POST['wcbulkorderquantity']; 
  82. $prod_id = $_POST['wcbulkorderid']; 
  83. $attributes = ''; 
  84. $i = 0; 
  85. foreach($prod_id as $key => $value) { 
  86. $variation_id = ''; 
  87. $product_id = $value; 
  88. if ( 'product_variation' == get_post_type( $product_id ) ) { 
  89. $variation_id = $product_id; 
  90. $product_id = wp_get_post_parent_id( $variation_id ); 
  91. $product = new WC_Product_Variation($variation_id); 
  92. $attributes = $product->get_variation_attributes(); 
  93. $attributes = isset($attributes) ? $attributes : ''; 
  94. $woocommerce->cart->add_to_cart($product_id, $prod_quantity[$key], $variation_id, $attributes, null); 
  95.  
  96. /** 
  97. * Create Bulk Order Form Shortcode 
  98. * Source: http://wordpress.stackexchange.com/questions/53280/woocommerce-add-a-product-to-cart-programmatically-via-js-or-php 
  99. */  
  100. public function wc_bulk_order_form ($atts) { 
  101. global $woocommerce; 
  102. self::$add_script = true; 
  103. extract( shortcode_atts( array( 
  104. 'rows' => isset($this->options['bulkorder_row_number']) ? $this->options['bulkorder_row_number'] : '',  
  105. 'price' => isset($this->options['display_price']) ? $this->options['display_price'] : '',  
  106. 'price_label' => isset($this->options['price_field_title']) ? $this->options['price_field_title']: '',  
  107. 'product_label' => isset($this->options['product_field_title']) ? $this->options['product_field_title'] : '',  
  108. 'quantity_label' => isset($this->options['quantity_field_title']) ? $this->options['quantity_field_title'] : '',  
  109. 'add_rows' => isset($this->options['new_row_button']) ? $this->options['new_row_button'] : '',  
  110. 'category' => '',  
  111. 'exclude' => '',  
  112. 'include' => '' 
  113. ), $atts ) ); 
  114. $i = 0; 
  115. $html = ''; 
  116. $items = ''; 
  117. $cart_url = $woocommerce->cart->get_cart_url(); 
  118.  
  119. if (!empty($_POST['wcbulkorderid'])) { 
  120. $quantity_check = array_filter($_POST['wcbulkorderquantity']); 
  121. if (empty($quantity_check)) { 
  122. $message = __("Make sure to set a quantity! Please try again.", "wcbulkorderform"); 
  123. wc_add_notice( $message, 'error' ); 
  124. } else { 
  125. if (($_POST['wcbulkorderid'][0] > 0) && ($_POST['wcbulkorderid'][1] > 0)) { 
  126. $items = 2; 
  127. } else if($_POST['wcbulkorderid'][0] > 0) { 
  128. $items = 1; 
  129. } else if((isset($_POST['submit'])) && ($_POST['wcbulkorderid'][0] <= 0)) { 
  130. $items = 0; 
  131. switch($items) { 
  132. case 0: 
  133. $message = __("Looks like there was an error. Please try again.", "wcbulkorderform"); 
  134. wc_add_notice( $message, 'error' ); 
  135. break; 
  136. case 1: 
  137. $message = '<a class="button wc-forward" href="'.$cart_url.'">View Cart</a>'.__("Your product was successfully added to your cart.", "wcbulkorderform"); 
  138. wc_add_notice( $message, 'success' ); 
  139. break; 
  140. case 2: 
  141. $message = '<a class="button wc-forward" href="'.$cart_url.'">'.__("View Cart</a> Your products were successfully added to your cart.", "wcbulkorderform"); 
  142. wc_add_notice( $message, 'success' ); 
  143. break; 
  144. wc_print_notices(); 
  145.  
  146. $html = '<form action="" method="post" id="BulkOrderForm" category="'.$category.'" included="'.$include.'" excluded="'.$exclude.'">'; 
  147. $html .= <<<HTML 
  148. <table class="wcbulkorderformtable"> 
  149. <tbody class="wcbulkorderformtbody"> 
  150. <tr> 
  151. <th class="wcbulkorder-title">$product_label</th> 
  152. <th class="wcbulkorder-quantity">$quantity_label</th> 
  153. HTML; 
  154. if ($price == 'true') { 
  155. $html .= '<th class="wcbulkorderprice">'.$price_label.'</th>'; 
  156. $html .= '</tr>'; 
  157. while($i < $rows) { 
  158. ++$i; 
  159. $html .= <<<HTML2 
  160. <tr class="wcbulkorderformtr"> 
  161. <td class="wcbulkorder-title"> 
  162. <i class="bulkorder_spinner"></i> 
  163. <input type="text" name="wcbulkorderproduct[]" class="wcbulkorderproduct" /> 
  164. </td> 
  165. <td class="wcbulkorder-quantity"> 
  166. <input type="text" name="wcbulkorderquantity[]" class="wcbulkorderquantity" /> 
  167. </td> 
  168. HTML2; 
  169. if($price == 'true') { 
  170. $html .= '<td class="wcbulkorderprice"></td>'; 
  171. $html .= <<<HTML7 
  172. <input type="hidden" name="wcbulkorderid[]" class="wcbulkorderid" value="" /> 
  173. </tr> 
  174. HTML7; 
  175. $html .= <<<HTML3 
  176. </tbody> 
  177. </table>  
  178. <table class="wcbulkorderformtable"> 
  179. <tbody> 
  180. HTML3; 
  181. if ($price == 'true') { 
  182. $html .= <<<HTML4 
  183. <tr class="wcbulkorderformtr"> 
  184. <td class="wcbulkorder-title"></td> 
  185. <td class="wcbulkorder-quantity"></td> 
  186. <td class="wcbulkorder-quantity"> 
  187. HTML4; 
  188. $html .= __( 'Total Price:' , 'wcbulkorderform' ); 
  189. $html .= <<<HTML6 
  190. </td> 
  191.  
  192. <td class="wcbulkorderpricetotal"></td> 
  193.  
  194. </tr> 
  195. HTML6; 
  196. $html .= '<tr>'; 
  197. $html .= '<td class="wcbulkorder-title"></td>'; 
  198. $html .= '<td class="wcbulkorder-quantity"></td>'; 
  199. $html .= '<td class="wcbulkorder-quantity">'; 
  200. if (($add_rows == 'true') && ($price == 'true')) { 
  201. $html .='<button class="wcbulkordernewrowprice">'.__( 'Add Row' , 'wcbulkorderform' ).'</button>'; 
  202. elseif (($add_rows == 'true') && ($price != 'true')) { 
  203. $html .='<button class="wcbulkordernewrow">'.__( 'Add Row' , 'wcbulkorderform' ).'</button>'; 
  204.  
  205. $html .='</td>'; 
  206. $html .='<td class="wcbulkorder-quantity"><input type="submit" value="'.__( 'Add To Cart' , 'wcbulkorderform' ).'" name="submit" /></td>'; 
  207. $html .= <<<HTML5 
  208. </tr> 
  209. </tbody> 
  210. </table> 
  211. </form> 
  212. HTML5; 
  213. return $html; 
  214.  
  215. function bulk_order_product_search() { 
  216. // Query for suggestions 
  217. $term = $_REQUEST['term']; 
  218. $category = !empty($_REQUEST['category']) ? explode(', ', $_REQUEST['category']) : array(); 
  219. $excluded_products = !empty($_REQUEST['excluded']) ? explode(', ', $_REQUEST['excluded']) : array(); 
  220. $included_products = !empty($_REQUEST['included']) ? explode(', ', $_REQUEST['included']) : array(); 
  221. $search_by = isset($this->options['search_by']) ? $this->options['search_by'] : '4'; 
  222. $max_items = isset($this->options['max_items']) ? $this->options['max_items'] : '-1'; 
  223. $excluded_products = apply_filters('wc_bulk_order_excluded_products', $excluded_products); 
  224. $included_products = apply_filters('wc_bulk_order_included_products', $included_products); 
  225. if (empty($term)) die(); 
  226. if(!empty($category)) { 
  227. if ( is_numeric( $term ) ) { 
  228.  
  229. if (($search_by == 2) || ($search_by == 4)) { 
  230. $products1 = array( 
  231. 'post_type' => array ('product', 'product_variation'),  
  232. 'post_status' => array('publish'),  
  233. 'posts_per_page' => $max_items,  
  234. 'post__in' => array(0, $term),  
  235. 'fields' => 'ids',  
  236. 'tax_query' => array( 
  237. array( 
  238. 'taxonomy' => 'product_cat',  
  239. 'field' => 'id',  
  240. 'terms' => $category,  
  241. ),  
  242. ),  
  243. ); 
  244.  
  245. $products2 = array( 
  246. 'post_type' => array ('product', 'product_variation'),  
  247. 'post_status' => array('publish'),  
  248. 'posts_per_page' => $max_items,  
  249. 'post_parent' => $term,  
  250. 'fields' => 'ids',  
  251. 'tax_query' => array( 
  252. array( 
  253. 'taxonomy' => 'product_cat',  
  254. 'field' => 'id',  
  255. 'terms' => $category,  
  256. ),  
  257. ),  
  258. ); 
  259. if (($search_by == 3) || ($search_by == 4)) { 
  260. $products4 = array( 
  261. 'post_type' => array ('product', 'product_variation'),  
  262. 'post_status' => array('publish'),  
  263. 'posts_per_page' => $max_items,  
  264. 's' => $term,  
  265. 'fields' => 'ids',  
  266. 'post__not_in' => $excluded_products,  
  267. 'post__in' => $included_products,  
  268. 'tax_query' => array( 
  269. array( 
  270. 'taxonomy' => 'product_cat',  
  271. 'field' => 'id',  
  272. 'terms' => $category,  
  273. ),  
  274. ),  
  275. ); 
  276. if (($search_by == 1) || ($search_by == 4)) { 
  277. $products3 = array( 
  278. 'post_type' => array ('product', 'product_variation'),  
  279. 'post_status' => array('publish'),  
  280. 'posts_per_page' => $max_items,  
  281. 'meta_query' => array( 
  282. array( 
  283. 'key' => '_sku',  
  284. 'value' => $term,  
  285. 'compare' => 'LIKE' 
  286. ),  
  287. 'fields' => 'ids',  
  288. 'post__not_in' => $excluded_products,  
  289. 'post__in' => $included_products,  
  290. 'tax_query' => array( 
  291. array( 
  292. 'taxonomy' => 'product_cat',  
  293. 'field' => 'id',  
  294. 'terms' => $category,  
  295. ),  
  296. ),  
  297. ); 
  298. if($search_by == 1) { 
  299. $products = array_unique(array_merge(get_posts( $products3 ) )); 
  300. } elseif ($search_by == 2) { 
  301. $products = array_unique(array_merge( get_posts( $products1 ), get_posts( $products2 ) )); 
  302. } elseif ($search_by == 3) { 
  303. $products = array_unique(array_merge(get_posts( $products4 ) )); 
  304. } else { 
  305. $products = array_unique(array_merge( get_posts( $products1 ), get_posts( $products2 ), get_posts( $products3 ), get_posts( $products4 ) )); 
  306. } else { 
  307.  
  308. if (($search_by == 1) || ($search_by == 4)) { 
  309. $products1 = array( 
  310. 'post_type' => array ('product', 'product_variation'),  
  311. 'post_status' => array('publish'),  
  312. 'posts_per_page' => $max_items,  
  313. 'meta_query' => array( 
  314. array( 
  315. 'key' => '_sku',  
  316. 'value' => $term,  
  317. 'compare' => 'LIKE' 
  318. ),  
  319. 'fields' => 'ids',  
  320. 'post__not_in' => $excluded_products,  
  321. 'post__in' => $included_products,  
  322. 'tax_query' => array( 
  323. array( 
  324. 'taxonomy' => 'product_cat',  
  325. 'field' => 'id',  
  326. 'terms' => $category,  
  327. ),  
  328. ),  
  329. ); 
  330. if (($search_by == 3) || ($search_by == 4)) { 
  331. $products2 = array( 
  332. 'post_type' => array ('product', 'product_variation'),  
  333. 'post_status' => array('publish'),  
  334. 'posts_per_page' => $max_items,  
  335. 's' => $term,  
  336. 'fields' => 'ids',  
  337. 'post__not_in' => $excluded_products,  
  338. 'post__in' => $included_products,  
  339. 'tax_query' => array( 
  340. array( 
  341. 'taxonomy' => 'product_cat',  
  342. 'field' => 'id',  
  343. 'terms' => $category,  
  344. ),  
  345. ),  
  346. ); 
  347.  
  348. if($search_by == 1) { 
  349. $products = array_unique(array_merge(get_posts( $products1 ) )); 
  350. } elseif($search_by == 3) { 
  351. $products = array_unique(array_merge(get_posts( $products2 ) )); 
  352. } else { 
  353. $products = array_unique(array_merge( get_posts( $products1 ), get_posts( $products2 ) )); 
  354. else { 
  355. if ( is_numeric( $term ) ) { 
  356.  
  357. if (($search_by == 2) || ($search_by == 4)) { 
  358.  
  359. $products1 = array( 
  360. 'post_type' => array ('product', 'product_variation'),  
  361. 'post_status' => array('publish'),  
  362. 'posts_per_page' => $max_items,  
  363. 'post__in' => array(0, $term),  
  364. 'fields' => 'ids' 
  365. ); 
  366.  
  367. $products2 = array( 
  368. 'post_type' => array ('product', 'product_variation'),  
  369. 'post_status' => array('publish'),  
  370. 'posts_per_page' => $max_items,  
  371. 'post_parent' => $term,  
  372. 'fields' => 'ids' 
  373. ); 
  374. if (($search_by == 3) || ($search_by == 4)) { 
  375. $products4 = array( 
  376. 'post_type' => array ('product', 'product_variation'),  
  377. 'post_status' => array('publish'),  
  378. 'posts_per_page' => $max_items,  
  379. 's' => $term,  
  380. 'fields' => 'ids',  
  381. 'post__not_in' => $excluded_products,  
  382. 'post__in' => $included_products 
  383. ); 
  384. if (($search_by == 1) || ($search_by == 4)) { 
  385. $products3 = array( 
  386. 'post_type' => array ('product', 'product_variation'),  
  387. 'post_status' => array('publish'),  
  388. 'posts_per_page' => $max_items,  
  389. 'meta_query' => array( 
  390. 'key' => '_sku',  
  391. 'value' => $term,  
  392. 'compare' => 'LIKE' 
  393. ),  
  394. 'fields' => 'ids',  
  395. 'post__not_in' => $excluded_products,  
  396. 'post__in' => $included_products 
  397. ); 
  398. if($search_by == 1) { 
  399. $products = array_unique(array_merge(get_posts( $products3 ) )); 
  400. } elseif ($search_by == 2) { 
  401. $products = array_unique(array_merge( get_posts( $products1 ), get_posts( $products2 ) )); 
  402. } elseif ($search_by == 3) { 
  403. $products = array_unique(array_merge(get_posts( $products4 ) )); 
  404. } else { 
  405. $products = array_unique(array_merge( get_posts( $products1 ), get_posts( $products2 ), get_posts( $products3 ), get_posts( $products4 ) )); 
  406. } else { 
  407.  
  408. if (($search_by == 1) || ($search_by == 4)) { 
  409. $products1 = array( 
  410. 'post_type' => array ('product', 'product_variation'),  
  411. 'post_status' => array('publish'),  
  412. 'posts_per_page' => $max_items,  
  413. 'meta_query' => array( 
  414. array( 
  415. 'key' => '_sku',  
  416. 'value' => $term,  
  417. 'compare' => 'LIKE' 
  418. ),  
  419. 'fields' => 'ids',  
  420. 'post__not_in' => $excluded_products,  
  421. 'post__in' => $included_products 
  422. ); 
  423. if (($search_by == 3) || ($search_by == 4)) { 
  424. $products2 = array( 
  425. 'post_type' => array ('product', 'product_variation'),  
  426. 'post_status' => array('publish'),  
  427. 'posts_per_page' => $max_items,  
  428. 's' => $term,  
  429. 'fields' => 'ids',  
  430. 'post__not_in' => $excluded_products,  
  431. 'post__in' => $included_products 
  432. ); 
  433.  
  434. if($search_by == 1) { 
  435. $products = array_unique(array_merge(get_posts( $products1 ) )); 
  436. } elseif($search_by == 3) { 
  437. $products = array_unique(array_merge(get_posts( $products2 ) )); 
  438. } else { 
  439. $products = array_unique(array_merge( get_posts( $products1 ), get_posts( $products2 ) )); 
  440. }  
  441.  
  442. // JSON encode and echo 
  443. // Initialise suggestions array 
  444.  
  445. global $post, $woocommerce, $product; 
  446. $suggestions = ''; 
  447. foreach ($products as $prod) { 
  448. $hide_product = 'false'; 
  449. $post_type = get_post_type($prod); 
  450. $child_args = array('post_parent' => $prod, 'post_type' => 'product_variation'); 
  451. $children = get_children( $child_args ); 
  452.  
  453. if(('product' == $post_type) && empty($children)) { 
  454. $product = get_product($prod); 
  455. $id = $product->id; 
  456. $price_html = $product->get_price_html(); 
  457. if(preg_match('/<ins>(.*?)<\/ins>/', $price_html)) {  
  458. preg_match('/<ins>(.*?)<\/ins>/', $price_html, $matches); 
  459. $price_html = $matches[1]; 
  460. $price_html = strip_tags($price_html); 
  461. $price = $price_html; 
  462. $sku = $product->get_sku(); 
  463. $title = get_the_title($product->id); 
  464. $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8'); 
  465. $img = wp_get_attachment_image_src( get_post_thumbnail_id( $id ), 'thumbnail'); 
  466. $img = $img[0]; 
  467. if (!empty($img)) { 
  468. $img = $img; 
  469. } else { 
  470. $img = apply_filters( 'woocommerce_placeholder_img_src', WC_Bulk_Order_Form_Compatibility::WC()->plugin_url() . '/assets/images/placeholder.png' ); 
  471. elseif(('product' == $post_type) && !empty($children)) { 
  472. $hide_product = 'true'; 
  473. elseif ( 'product_variation' == $post_type ) { 
  474. $product = new WC_Product_Variation($prod); 
  475. $parent = get_product($prod); 
  476. $id = $product->variation_id; 
  477. $price_html = $product->get_price_html(); 
  478. if(preg_match('/<ins>(.*?)<\/ins>/', $price_html)) {  
  479. preg_match('/<ins>(.*?)<\/ins>/', $price_html, $matches); 
  480. $price_html = $matches[1]; 
  481. $price_html = strip_tags($price_html); 
  482. $price = $price_html; 
  483. $sku = $product->get_sku(); 
  484. $title = $product->get_title(); 
  485. $attributes = $product->get_variation_attributes(); 
  486. $img = apply_filters( 'woocommerce_placeholder_img_src', WC_Bulk_Order_Form_Compatibility::WC()->plugin_url() . '/assets/images/placeholder.png' ); 
  487. foreach ( $attributes as $name => $value) { 
  488. $name = str_ireplace("attribute_", "", $name); 
  489. $terms = get_the_terms( $product->id, $name); 
  490. foreach ( $terms as $term ) { 
  491. if(strtolower($term->name) == $value) { 
  492. $value = $term->name; 
  493. $attr_name = $name;  
  494. $attr_value = $value; 
  495. $attr_value = str_replace('-', ' ', $value); 
  496. if($this->options['attribute_style'] === 'true') { 
  497. $title .= ' '.$attr_value.' '; 
  498. } else { 
  499. if (strstr($attr_name, 'pa_')) { 
  500. $atts = get_the_terms($parent->id , $attr_name); 
  501. $attr_name_clean = WC_Bulk_Order_Form_Compatibility::wc_attribute_label($attr_name); 
  502. else { 
  503. $np = explode("-", str_replace("attribute_", "", $attr_name)); 
  504. $attr_name_clean = ucwords(implode(" ", $np)); 
  505. $attr_name_clean = str_replace("attribute_pa_", "", $attr_name_clean); 
  506. $attr_name_clean = str_replace("Attribute_pa_", "", $attr_name_clean); 
  507. $title .= " - " . $attr_name_clean . ": " . $attr_value; 
  508. $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8'); 
  509. $parent_image = wp_get_attachment_image_src( get_post_thumbnail_id( $id ), 'thumbnail'); 
  510. $parent_image = $parent_image[0]; 
  511. $img = wp_get_attachment_image_src( get_post_thumbnail_id( $parent->id ), 'thumbnail'); 
  512. $img = $img[0]; 
  513. if (!empty($img)) { 
  514. $img = $img; 
  515. } elseif (!empty($parent_image)) { 
  516. $img = $parent_image; 
  517. } else { 
  518. $img = apply_filters( 'woocommerce_placeholder_img_src', WC_Bulk_Order_Form_Compatibility::WC()->plugin_url() . '/assets/images/placeholder.png' ); 
  519.  
  520. if($hide_product == 'false') { 
  521. $symbol = get_woocommerce_currency_symbol(); 
  522. $symbol = html_entity_decode($symbol, ENT_COMPAT, 'UTF-8'); 
  523. $price = html_entity_decode($price, ENT_COMPAT, 'UTF-8'); 
  524. // Initialise suggestion array 
  525. $suggestion = array(); 
  526. $switch_data = isset($this->options['search_format']) ? $this->options['search_format'] : '1'; 
  527. $price = apply_filters('wc_bulk_order_form_price' , $price, $product); 
  528. switch ($switch_data) { 
  529. case 1: 
  530. if (!empty($sku)) { 
  531. $label = $sku.' - '.$title. ' - '.$price; 
  532. } else { 
  533. $label = $title. ' - '.$price; 
  534. break; 
  535. case 2: 
  536. if (!empty($sku)) { 
  537. $label = $title. ' - '.$price.' - '.$sku; 
  538. } else { 
  539. $label = $title. ' - '.$price; 
  540. break; 
  541. case 3: 
  542. $label = $title .' - '.$price; 
  543. break; 
  544. case 4: 
  545. if (!empty($sku)) { 
  546. $label = $title. ' - '.$sku; 
  547. } else { 
  548. $label = $title; 
  549. break; 
  550. case 5: 
  551. $label = $title; 
  552. break; 
  553. $suggestion['label'] = apply_filters('wc_bulk_order_form_label', $label, $price, $title, $sku, $symbol); 
  554. $suggestion['price'] = $price; 
  555. $suggestion['symbol'] = $symbol; 
  556. $suggestion['id'] = $id; 
  557. $suggestion['imgsrc'] = $img; 
  558. if (!empty($variation_id)) { 
  559. $suggestion['variation_id'] = $variation_id; 
  560. // Add suggestion to suggestions array 
  561. $suggestions[]= $suggestion; 
  562. // JSON encode and echo 
  563. $response = $_GET["callback"] . "(" . json_encode($suggestions) . ")"; 
  564. //print_r($response); 
  565. echo $response; 
  566. // Don't forget to exit! 
  567. exit; 
  568.  
  569. /** 
  570. class Register_Standard_Template { 
  571. public function __construct() { 
  572. register_activation_hook( __FILE__, array(&$this, 'default_settings')); 
  573. } 
  574. public function default_settings() { 
  575. global $options; 
  576. $sections = get_option('wcbulkorderform_sections'); 
  577. if(empty($sections['templates'])) { 
  578. $sections['templates'] = array(); 
  579. } 
  580. if(!in_array('Standard', $sections['templates'])) { 
  581. $sections['templates'][] = 'Standard'; 
  582. } 
  583. update_option('wcbulkorderform_sections', $sections); 
  584. } 
  585. } 
  586. $Register_Standard_Template = new Register_Standard_Template(); 
  587. */ 
.