WCBulkOrderForm_Standard_Template

The WooCommerce Bulk Order Form WCBulkOrderForm Standard Template class.

Defined (1)

The class is defined in the following location(s).

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