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