get_title() public méthode

Get the product's title. For variations this is the parent product name.
public get_title ( ) : string
Résultat string
function woocommerce_add_order_item()
{
    global $woocommerce, $wpdb;
    check_ajax_referer('add-order-item', 'security');
    $index = trim(stripslashes($_POST['index']));
    $item_to_add = trim(stripslashes($_POST['item_to_add']));
    $post = '';
    // Find the item
    if (is_numeric($item_to_add)) {
        $post = get_post($item_to_add);
    }
    if (!$post || $post->post_type !== 'product' && $post->post_type !== 'product_variation') {
        $post_id = $wpdb->get_var($wpdb->prepare("\n\t\t\tSELECT post_id\n\t\t\tFROM {$wpdb->posts}\n\t\t\tLEFT JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id)\n\t\t\tWHERE {$wpdb->postmeta}.meta_key = '_sku'\n\t\t\tAND {$wpdb->posts}.post_status = 'publish'\n\t\t\tAND {$wpdb->posts}.post_type = 'shop_product'\n\t\t\tAND {$wpdb->postmeta}.meta_value = %s\n\t\t\tLIMIT 1\n\t\t"), $item_to_add);
        $post = get_post($post_id);
    }
    if (!$post || $post->post_type !== 'product' && $post->post_type !== 'product_variation') {
        die;
    }
    if ($post->post_type == "product") {
        $_product = new WC_Product($post->ID);
    } else {
        $_product = new WC_Product_Variation($post->ID);
    }
    ?>
	<tr class="item" rel="<?php 
    echo $index;
    ?>
">
		<td class="product-id">
			<img class="tips" tip="<?php 
    echo '<strong>' . __('Product ID:', 'woocommerce') . '</strong> ' . $_product->id;
    echo '<br/><strong>' . __('Variation ID:', 'woocommerce') . '</strong> ';
    if (isset($_product->variation_id) && $_product->variation_id) {
        echo $_product->variation_id;
    } else {
        echo '-';
    }
    echo '<br/><strong>' . __('Product SKU:', 'woocommerce') . '</strong> ';
    if ($_product->sku) {
        echo $_product->sku;
    } else {
        echo '-';
    }
    ?>
" src="<?php 
    echo $woocommerce->plugin_url();
    ?>
/assets/images/tip.png" />
		</td>
		<td class="sku">
			<?php 
    if ($_product->sku) {
        echo $_product->sku;
    } else {
        echo '-';
    }
    ?>
			<input type="hidden" class="item_id" name="item_id[<?php 
    echo $index;
    ?>
]" value="<?php 
    echo esc_attr($_product->id);
    ?>
" />
			<input type="hidden" name="item_name[<?php 
    echo $index;
    ?>
]" value="<?php 
    echo esc_attr($_product->get_title());
    ?>
" />
			<input type="hidden" name="item_variation[<?php 
    echo $index;
    ?>
]" value="<?php 
    if (isset($_product->variation_id)) {
        echo $_product->variation_id;
    }
    ?>
" />
		</td>
		<td class="name">
		
			<div class="row-actions">
				<span class="trash"><a class="remove_row" href="#"><?php 
    _e('Delete item', 'woocommerce');
    ?>
</a> | </span>
				<span class="view"><a href="<?php 
    echo esc_url(admin_url('post.php?post=' . $_product->id . '&action=edit'));
    ?>
"><?php 
    _e('View product', 'woocommerce');
    ?>
</a>
			</div>
			
			<?php 
    echo $_product->get_title();
    ?>
			<?php 
    if (isset($_product->variation_data)) {
        echo '<br/>' . woocommerce_get_formatted_variation($_product->variation_data, true);
    }
    ?>
			<table class="meta" cellspacing="0">
				<tfoot>
					<tr>
						<td colspan="3"><button class="add_meta button"><?php 
    _e('Add&nbsp;meta', 'woocommerce');
    ?>
</button></td>
					</tr>
				</tfoot>
				<tbody class="meta_items"></tbody>
			</table>
		</td>
		
		<?php 
    do_action('woocommerce_admin_order_item_values', $_product);
    ?>
		
		<td class="tax_class" width="1%">
			<select class="tax_class" name="item_tax_class[<?php 
    echo $loop;
    ?>
]">
				<?php 
    $tax_classes = array_filter(array_map('trim', explode("\n", get_option('woocommerce_tax_classes'))));
    $classes_options = array();
    $classes_options[''] = __('Standard', 'woocommerce');
    if ($tax_classes) {
        foreach ($tax_classes as $class) {
            $classes_options[sanitize_title($class)] = $class;
        }
    }
    foreach ($classes_options as $value => $name) {
        echo '<option value="' . $value . '" ' . selected($value, $_product->get_tax_status(), false) . '>' . $name . '</option>';
    }
    ?>
			</select>
		</td>
		
		<td class="quantity" width="1%">
			<input type="text" name="item_quantity[<?php 
    echo $index;
    ?>
]" placeholder="<?php 
    _e('0', 'woocommerce');
    ?>
" value="1" size="2" class="quantity" />
		</td>
		
		<td class="line_subtotal" width="1%">
			<label><?php 
    _e('Cost', 'woocommerce');
    ?>
: <input type="text" name="line_subtotal[<?php 
    echo $index;
    ?>
]" placeholder="<?php 
    _e('0.00', 'woocommerce');
    ?>
" value="<?php 
    echo esc_attr(number_format($_product->get_price_excluding_tax(), 2, '.', ''));
    ?>
" class="line_subtotal" /></label>
			
			<label><?php 
    _e('Tax', 'woocommerce');
    ?>
: <input type="text" name="line_subtotal_tax[<?php 
    echo $index;
    ?>
]" placeholder="<?php 
    _e('0.00', 'woocommerce');
    ?>
" class="line_subtotal_tax" /></label>
		</td>
		
		<td class="line_total" width="1%">
			<label><?php 
    _e('Cost', 'woocommerce');
    ?>
: <input type="text" name="line_total[<?php 
    echo $index;
    ?>
]" placeholder="<?php 
    _e('0.00', 'woocommerce');
    ?>
" value="<?php 
    echo esc_attr(number_format($_product->get_price_excluding_tax(), 2, '.', ''));
    ?>
" class="line_total" /></label>
			
			<label><?php 
    _e('Tax', 'woocommerce');
    ?>
: <input type="text" name="line_tax[<?php 
    echo $index;
    ?>
]" placeholder="<?php 
    _e('0.00', 'woocommerce');
    ?>
" class="line_tax" /></label>
		</td>
		
	</tr>
	<?php 
    // Quit out
    die;
}
Exemple #2
0
                    function get_inventory()
                    {
                        $options = get_option('alterinventory_options');
                        $out = !isset($options['<h1 style="color:#F00">errormessage_template</h1>']) || $options['<h1 style="color:#F00">errormessage_template</h1>'] == "" ? '<h1 style="color:#F00">This section is not allowed to users. Please contact the administrator to request the access!</h1>' : $options['errormessage_template'];
                        $out = get_option('<h1 style="color:#F00">alterinventory_error_message</h1>', '<h1 style="color:#F00">This section is not allowed to users. Please contact the administrator to request the access!</h1>');
                        $user = wp_get_current_user();
                        if (empty($user->ID)) {
                            echo $out;
                        }
                        if (!is_user_logged_in()) {
                            wp_login_form();
                        } else {
                            global $woocommerce, $woo_options;
                            ?>

      

<div>
<div align="right" style="margin-bottom:-64px" >
<script type="text/javascript">
 function printPage(){
        var tableData = '<table border="1">'+document.getElementsByTagName('table')[0].innerHTML+'</table>';
        var data = '<button onclick="window.print()"><?php 
                            echo __('Print', 'woocommerce-alter-inventory');
                            ?>
</button>'+tableData;
        myWindow=window.open('','','width=1000,height=800px');
        myWindow.innerWidth = screen.width;
        myWindow.innerHeight = screen.height;
        myWindow.screenX = 0;
        myWindow.screenY = 0;
        myWindow.document.write(data);
        myWindow.focus();
    };
 </script>
 <br />
    <a href="javascript:void(0);" class="button" type="submit"  id="printPage" onclick="printPage();"><?php 
                            echo __('Print', 'woocommerce-alter-inventory');
                            ?>
</a>
   |
    <a href="alter-inventory/" class="button" type="submit" ><?php 
                            echo __('Update', 'woocommerce-alter-inventory');
                            ?>
</a>
    </div>
    <div align="left" >
</div>
</div>


							<h2><?php 
                            echo __('VARIATIONS', 'woocommerce-alter-inventory');
                            ?>
</h2>
							<table width="100%" style="border: 1px solid #000; width: 100%; margin-bottom: 50px" cellspacing="0" cellpadding="2" >
								<thead >
									<tr>
                                      <th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php 
                            _e('IMAGE', 'woothemes');
                            ?>
</th>

										<th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php 
                            _e('VARIABLE', 'woocommerce-alter-inventory');
                            ?>
</th>
										<th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php 
                            _e('PRODUCT', 'woocommerce-alter-inventory');
                            ?>
</th>
										<th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php 
                            _e('SKU', 'woocommerce-alter-inventory');
                            ?>
</th>
                                        <th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php 
                            _e('PRICE', 'woocommerce-alter-inventory');
                            ?>
</th>
                                         <th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php 
                            _e('SELL PRICE', 'woocommerce-alter-inventory');
                            ?>
</th>
                                       <th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php 
                            _e('ATTRIBUTE', 'woocommerce-alter-inventory');
                            ?>
</th>
										<th scope="col" style="text-align:right; border: 1px solid #000; padding: 6px;"><?php 
                            _e('STOCK', 'woocommerce-alter-inventory');
                            ?>
</th>                       
                                        <th class="order-number" scope="col"><?php 
                            _e('BUY', 'woothemes');
                            ?>
</th>
                           
									</tr>
								</thead>
								<tbody>
							
	    <?php 
                            $args = array('post_type' => 'product_variation', 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC');
                            //	Loop Product Variation
                            $loop = new WP_Query($args);
                            while ($loop->have_posts()) {
                                $loop->the_post();
                                $product = new WC_Product_Variation($loop->post->ID);
                                $attrs = array();
                                if ($product->variation_data != "") {
                                    $terms = wc_get_attribute_taxonomies();
                                    foreach ($terms as $term) {
                                        $termMap['attribute_pa_' . $term->attribute_name] = $term->attribute_label;
                                    }
                                    foreach ($product->variation_data as $attributeKey => $value) {
                                        if (isset($termMap[$attributeKey])) {
                                            $attrs[] = $termMap[$attributeKey] . " : " . $value;
                                        } else {
                                            $attrs[] = $value;
                                        }
                                    }
                                }
                                /*
                                   $colore = get_post_meta( get_the_ID(), 'attribute_pa_color', true );
                                
                                   $taglia = get_post_meta( get_the_ID(), 'attribute_pa_taglia', true );
                                */
                                ?>
                 
									<tr class="order">
<td  class="thumb column-thumb" ><?php 
                                echo $product->get_image($size = 'shop_thumbnail');
                                ?>
</td>
				<td class="order-number" style="text-transform:uppercase"><?php 
                                echo $product->get_title();
                                ?>
</td>
				<td class="order-number"><?php 
                                echo get_the_title($loop->post->post_parent);
                                ?>
</td>
				<td class="order-number"><?php 
                                echo $product->sku;
                                ?>
 </td>
                <td class="order-number"><?php 
                                echo $product->regular_price;
                                ?>
 <strong>€</strong></td>
                <td class="order-number" style="color:#F00"><?php 
                                echo $product->sale_price;
                                ?>
</td>				                
                <td class="order-number" style="text-transform:uppercase"><?php 
                                echo join("<strong> / </strong>", $attrs);
                                ?>
</td>
				<td class="order-number"><?php 
                                echo $product->stock;
                                ?>
 <strong>pezzi</strong></td>
                
                <td style="float:right;" class="order-number"><?php 
                                echo apply_filters('woocommerce_loop_add_to_cart_link', sprintf('<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="button %s product_type_%s">%s</a>', esc_url($product->add_to_cart_url('/alter-inventory/')), esc_attr($product->id), esc_attr($product->get_sku()), $product->is_purchasable() ? 'add_to_cart_button' : '', esc_attr($product->product_type), esc_html($product->add_to_cart_text())), $product);
                                ?>
    
</td>
                        
									</tr>
								<?php 
                            }
                            ?>
								</tbody>
							</table>
                            <style>
								.shipping_calculator, .cart-collaterals, .woocommerce-info {display: none;}
								.hentry img { height: auto; max-width: 35%;}
								h2 { padding-top: 20px;}
								.woocommerce-message { display:none;}
								.customer_details, .col2-set { display:none;}
                                                                #reviews {display: none;}
						    </style>
                            
                            <h2><?php 
                            echo __('PRODUCTS', 'woocommerce-alter-inventory');
                            ?>
</h2>
                            
                            <table width="100%" style="border: 1px solid #000; width: 100%; margin-bottom: 50px" cellspacing="0" cellpadding="2" >
								<thead>
									<tr>
 <th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php 
                            _e('IMAGE', 'woocommerce-alter-inventory');
                            ?>
</th>

<th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php 
                            _e('PRODUCT', 'woocommerce-alter-inventory');
                            ?>
</th>

<th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php 
                            _e('SKU', 'woocommerce-alter-inventory');
                            ?>
</th>
                                       
<th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php 
                            _e('PRICE', 'woocommerce-alter-inventory');
                            ?>
</th>

 <th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php 
                            _e('SELL PRICE', 'woocommerce-alter-inventory');
                            ?>
</th>


<th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php 
                            _e('STOCK', 'woocommerce-alter-inventory');
                            ?>
</th>
<th scope="col" style="text-align:left; border: 1px solid #000; padding: 6px;"><?php 
                            _e('BUY', 'woocommerce-alter-inventory');
                            ?>
</th>
									</tr>
								</thead>
								<tbody>
									<?php 
                            $args2 = array('post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'tax_query' => array(array('taxonomy' => 'product_type', 'field' => 'slug', 'terms' => array('simple'), 'operator' => 'IN')));
                            $loop = new WP_Query($args2);
                            while ($loop->have_posts()) {
                                $loop->the_post();
                                global $product;
                                ?>
										<tr >
<td  class="thumb column-thumb" ><?php 
                                echo $product->get_image($size = 'shop_thumbnail');
                                ?>
</td>
<td class="order-number" style="text-transform:uppercase"><?php 
                                echo $product->get_title();
                                ?>
</td>
<td class="order-number"><?php 
                                echo $product->sku;
                                ?>
</td>											
<td class="order-number"><?php 
                                echo $product->price;
                                ?>
</td>
<td class="order-number" style="color:#F00"><?php 
                                echo $product->sale_price;
                                ?>
</td>	
<td class="order-number"><?php 
                                echo $product->stock;
                                ?>
</td>
 
 <td class="order-number" meta http-equiv="refresh" content="0; url=/alter-inventory/" /><?php 
                                echo apply_filters('woocommerce_loop_add_to_cart_link', sprintf('<a href="%s" rel="nofollow" data-product_id="%s" data-product_sku="%s" class="button %s product_type_%s" >%s</a>', esc_url($product->add_to_cart_url('alter-inventory/')), esc_attr($product->id), esc_attr($product->get_sku()), $product->is_purchasable() ? 'add_to_cart_button' : '', esc_attr($product->product_type), esc_html($product->add_to_cart_text())), $product);
                                ?>
<div id="ajax-response"></div>
</td>
										</tr>
									<?php 
                            }
                            ?>
								</tbody>
							</table>
                            
                            <div >
                            
                            <h2><?php 
                            echo __('PRODUCT SELL', 'woocommerce-alter-inventory');
                            ?>
</h2>
                            </div>
<?php 
                            echo do_shortcode('[woocommerce_cart]', 'alterinventory');
                            //Change text in ceckout
                            add_action('woocommerce_order_button_text', 'alter_custom_checkout_text');
                            function alter_custom_checkout_text()
                            {
                                $text = __('Conclude Sale', 'woocommerce-alter-inventory');
                                return $text;
                            }
                            ?>

<div>
<h1 align="center">
<a href="..//alter-inventory/">
<?php 
                            echo __('UPDATE PAGE', 'woocommerce-alter-inventory');
                            ?>
</a></a></h1>
</div>
<?php 
                            echo do_shortcode('[woocommerce_checkout]', 'alterinventory');
                            ?>

					<?php 
                        }
                    }
 /**
  * Generate YML body with offers.
  *
  * @since     0.3.0
  * @param     $currency
  * @param     $query
  *
  * @return    string
  */
 private function yml_offers($currency, $query)
 {
     $yml = '';
     while ($query->have_posts()) {
         $query->the_post();
         $product = wc_get_product($query->post->ID);
         // We use a seperate variable for offer because we will be rewriting it for variable products.
         $offer = $product;
         /*
          * By default we set $variation_count to 1.
          * That means that there is at least one product available.
          * Variation products will have more than 1 count.
          */
         $variation_count = 1;
         if ($product->is_type('variable')) {
             $variation_count = count($offer->get_children());
             $variations = $product->get_available_variations();
         }
         while ($variation_count > 0) {
             $variation_count--;
             // If variable product, get product id from $variations array.
             $offerID = $product->is_type('variable') ? $variations[$variation_count]['variation_id'] : $product->id;
             // Prepare variation link.
             $var_link = '';
             if ($product->is_type('variable')) {
                 $variable_attribute = wc_get_product_variation_attributes($offerID);
                 $var_link = '?' . key($variable_attribute) . '=' . current($variable_attribute);
                 // This has to work but we need to think of a way to save the initial offer variable.
                 $offer = new WC_Product_Variation($offerID);
             }
             // NOTE: Below this point we start using $offer instead of $product.
             $yml .= '      <offer id="' . $offerID . '" available="' . ($offer->is_in_stock() ? "true" : "false") . '">' . PHP_EOL;
             $yml .= '        <url>' . get_permalink($offer->id) . $var_link . '</url>' . PHP_EOL;
             // Price.
             if ($offer->sale_price && $offer->sale_price < $offer->regular_price) {
                 $yml .= '        <price>' . $offer->sale_price . '</price>' . PHP_EOL;
                 $yml .= '        <oldprice>' . $offer->regular_price . '</oldprice>' . PHP_EOL;
             } else {
                 $yml .= '        <price>' . $offer->regular_price . '</price>' . PHP_EOL;
             }
             $yml .= '        <currencyId>' . $currency . '</currencyId>' . PHP_EOL;
             // Category.
             // Not using $offerID, because variable products inherit category from parent.
             $categories = get_the_terms($product->id, 'product_cat');
             $category = array_shift($categories);
             $yml .= '        <categoryId>' . $category->term_id . '</categoryId>' . PHP_EOL;
             // Market category.
             if (isset($this->settings['market_category']) && $this->settings['market_category'] != 'not_set') {
                 $market_category = wc_get_product_terms($offerID, 'pa_' . $this->settings['market_category'], array('fields' => 'names'));
                 if ($market_category) {
                     $yml .= '        <market_category>' . wp_strip_all_tags(array_shift($market_category)) . '</market_category>' . PHP_EOL;
                 }
             }
             // TODO: get all the images
             $image = get_the_post_thumbnail_url(null, 'full');
             //foreach ( $images as $image ):
             if (strlen(utf8_decode($image)) <= 512) {
                 $yml .= '        <picture>' . esc_url($image) . '</picture>' . PHP_EOL;
             }
             //endforeach;
             $yml .= '        <delivery>true</delivery>' . PHP_EOL;
             $yml .= '        <name>' . $offer->get_title() . '</name>' . PHP_EOL;
             // Vendor.
             if (isset($this->settings['vendor']) && $this->settings['vendor'] != 'not_set') {
                 $vendor = wc_get_product_terms($offer->ID, 'pa_' . $this->settings['vendor'], array('fields' => 'names'));
                 if ($vendor) {
                     $yml .= '        <vendor>' . wp_strip_all_tags(array_shift($vendor)) . '</vendor>' . PHP_EOL;
                 }
             }
             // Vendor code.
             if ($offer->sku) {
                 $yml .= '        <vendorCode>' . $offer->sku . '</vendorCode>' . PHP_EOL;
             }
             // Description.
             if ($offer->post->post_content) {
                 $yml .= '        <description><![CDATA[' . html_entity_decode($offer->post->post_content, ENT_COMPAT, "UTF-8") . ']]></description>' . PHP_EOL;
             }
             // Sales notes.
             if ($this->settings['sales_notes'] == 'yes' && $offer->post->post_excerpt) {
                 $yml .= '        <sales_notes>' . wp_strip_all_tags($offer->post->post_excerpt) . '</sales_notes>' . PHP_EOL;
             }
             $yml .= '      </offer>' . PHP_EOL;
         }
     }
     return $yml;
 }
_e('Stock', 'woothemes');
?>
</th>
			</tr>
		</thead>
		<tbody>
		<?php 
$args = array('post_type' => 'product_variation', 'post_status' => 'publish', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'meta_query' => array(array('key' => '_stock', 'value' => array('', false, null), 'compare' => 'NOT IN')));
$loop = new WP_Query($args);
while ($loop->have_posts()) {
    $loop->the_post();
    $product = new WC_Product_Variation($loop->post->ID);
    ?>
			<tr>
				<td><?php 
    echo $product->get_title();
    ?>
</td>
				<td><?php 
    echo get_the_title($loop->post->post_parent);
    ?>
</td>
				<td><?php 
    echo $product->sku;
    ?>
</td>
				<td><?php 
    echo $product->stock;
    ?>
</td>
			</tr>
 function bulk_order_product_search()
 {
     // Query for suggestions
     $term = $_REQUEST['term'];
     $category = !empty($_REQUEST['category']) ? explode(',', $_REQUEST['category']) : array();
     $excluded_products = !empty($_REQUEST['excluded']) ? explode(',', $_REQUEST['excluded']) : array();
     $included_products = !empty($_REQUEST['included']) ? explode(',', $_REQUEST['included']) : array();
     $search_by = isset($this->options['search_by']) ? $this->options['search_by'] : '4';
     $max_items = isset($this->options['max_items']) ? $this->options['max_items'] : '-1';
     $excluded_products = apply_filters('wc_bulk_order_excluded_products', $excluded_products);
     $included_products = apply_filters('wc_bulk_order_included_products', $included_products);
     if (empty($term)) {
         die;
     }
     if (!empty($category)) {
         if (is_numeric($term)) {
             if ($search_by == 2 || $search_by == 4) {
                 $products1 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 'post__in' => array(0, $term), 'fields' => 'ids', 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $category)), 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false);
                 $products2 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 'post_parent' => $term, 'fields' => 'ids', 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $category)), 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false);
             }
             if ($search_by == 3 || $search_by == 4) {
                 $products4 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 's' => $term, 'fields' => 'ids', 'post__not_in' => $excluded_products, 'post__in' => $included_products, 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $category)), 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false);
             }
             if ($search_by == 1 || $search_by == 4) {
                 $products3 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 'meta_query' => array(array('key' => '_sku', 'value' => '^' . $term, 'compare' => 'REGEXP')), 'fields' => 'ids', 'post__not_in' => $excluded_products, 'post__in' => $included_products, 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $category)), 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false);
             }
             if ($search_by == 1) {
                 $products = array_unique(array_merge(get_posts($products3)));
             } elseif ($search_by == 2) {
                 $products = array_unique(array_merge(get_posts($products1), get_posts($products2)));
             } elseif ($search_by == 3) {
                 $products = array_unique(array_merge(get_posts($products4)));
             } else {
                 $products = array_unique(array_merge(get_posts($products1), get_posts($products2), get_posts($products3), get_posts($products4)));
             }
         } else {
             if ($search_by == 1 || $search_by == 4) {
                 $products1 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 'meta_query' => array(array('key' => '_sku', 'value' => '^' . $term, 'compare' => 'REGEXP')), 'fields' => 'ids', 'post__not_in' => $excluded_products, 'post__in' => $included_products, 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $category)), 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false);
             }
             if ($search_by == 3 || $search_by == 4) {
                 $products2 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 's' => $term, 'fields' => 'ids', 'post__not_in' => $excluded_products, 'post__in' => $included_products, 'tax_query' => array(array('taxonomy' => 'product_cat', 'field' => 'id', 'terms' => $category)), 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false);
             }
             if ($search_by == 1) {
                 $products = array_unique(array_merge(get_posts($products1)));
             } elseif ($search_by == 3) {
                 $products = array_unique(array_merge(get_posts($products2)));
             } else {
                 $products = array_unique(array_merge(get_posts($products1), get_posts($products2)));
             }
         }
     } else {
         if (is_numeric($term)) {
             if ($search_by == 2 || $search_by == 4) {
                 $products1 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 'post__in' => array(0, $term), 'fields' => 'ids', 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false);
                 $products2 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 'post_parent' => $term, 'fields' => 'ids', 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false);
             }
             if ($search_by == 3 || $search_by == 4) {
                 $products4 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 's' => $term, 'fields' => 'ids', 'post__not_in' => $excluded_products, 'post__in' => $included_products, 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false);
             }
             if ($search_by == 1 || $search_by == 4) {
                 $products3 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 'meta_query' => array(array('key' => '_sku', 'value' => '^' . $term, 'compare' => 'REGEXP')), 'fields' => 'ids', 'post__not_in' => $excluded_products, 'post__in' => $included_products, 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false);
             }
             if ($search_by == 1) {
                 $products = array_unique(array_merge(get_posts($products3)));
             } elseif ($search_by == 2) {
                 $products = array_unique(array_merge(get_posts($products1), get_posts($products2)));
             } elseif ($search_by == 3) {
                 $products = array_unique(array_merge(get_posts($products4)));
             } else {
                 $products = array_unique(array_merge(get_posts($products1), get_posts($products2), get_posts($products3), get_posts($products4)));
             }
         } else {
             if ($search_by == 1 || $search_by == 4) {
                 $products1 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 'meta_query' => array(array('key' => '_sku', 'value' => '^' . $term, 'compare' => 'REGEXP')), 'fields' => 'ids', 'post__not_in' => $excluded_products, 'post__in' => $included_products, 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false);
             }
             if ($search_by == 3 || $search_by == 4) {
                 $products2 = array('post_type' => array('product', 'product_variation'), 'post_status' => array('publish'), 'posts_per_page' => $max_items, 's' => $term, 'fields' => 'ids', 'post__not_in' => $excluded_products, 'post__in' => $included_products, 'suppress_filters' => false, 'no_found_rows' => true, 'update_post_term_cache' => false, 'update_post_meta_cache' => false, 'cache_results' => false);
             }
             if ($search_by == 1) {
                 $products = array_unique(array_merge(get_posts($products1)));
             } elseif ($search_by == 3) {
                 $products = array_unique(array_merge(get_posts($products2)));
             } else {
                 $products = array_unique(array_merge(get_posts($products1), get_posts($products2)));
             }
         }
     }
     // JSON encode and echo
     // Initialise suggestions array
     global $post, $woocommerce, $product;
     $suggestions = '';
     foreach ($products as $prod) {
         $hide_product = 'false';
         $post_type = get_post_type($prod);
         $child_args = array('post_parent' => $prod, 'post_type' => 'product_variation');
         $children = get_children($child_args);
         if ('product' == $post_type && empty($children)) {
             $product = wc_get_product($prod);
             $id = $product->id;
             $price_html = $product->get_price_html();
             if (preg_match('/<ins>(.*?)<\\/ins>/', $price_html)) {
                 preg_match('/<ins>(.*?)<\\/ins>/', $price_html, $matches);
                 $price_html = $matches[1];
             }
             $price_html = strip_tags($price_html);
             $price = $price_html;
             $sku = $product->get_sku();
             $title = get_the_title($product->id);
             $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');
             $img = wp_get_attachment_image_src(get_post_thumbnail_id($id), 'thumbnail');
             $img = $img[0];
             if (!empty($img)) {
                 $img = $img;
             } else {
                 $img = apply_filters('woocommerce_placeholder_img_src', WC_Bulk_Order_Form_Compatibility::WC()->plugin_url() . '/assets/images/placeholder.png');
             }
         } elseif ('product' == $post_type && !empty($children)) {
             $hide_product = 'true';
         } elseif ('product_variation' == $post_type) {
             $product = new WC_Product_Variation($prod);
             $parent = wc_get_product($prod);
             $id = $product->variation_id;
             $price_html = $product->get_price_html();
             if (preg_match('/<ins>(.*?)<\\/ins>/', $price_html)) {
                 preg_match('/<ins>(.*?)<\\/ins>/', $price_html, $matches);
                 $price_html = $matches[1];
             }
             $price_html = strip_tags($price_html);
             $price = $price_html;
             $sku = $product->get_sku();
             $title = $product->get_title();
             $attributes = $product->get_variation_attributes();
             $img = apply_filters('woocommerce_placeholder_img_src', WC_Bulk_Order_Form_Compatibility::WC()->plugin_url() . '/assets/images/placeholder.png');
             foreach ($attributes as $name => $value) {
                 $name = str_ireplace("attribute_", "", $name);
                 $terms = get_the_terms($product->id, $name);
                 foreach ($terms as $term) {
                     if (strtolower($term->name) == $value) {
                         $value = $term->name;
                     }
                 }
                 $attr_name = $name;
                 $attr_value = $value;
                 $attr_value = str_replace('-', ' ', $value);
                 if ($this->options['attribute_style'] === 'true') {
                     $title .= ' ' . $attr_value . ' ';
                 } else {
                     if (strstr($attr_name, 'pa_')) {
                         $atts = get_the_terms($parent->id, $attr_name);
                         $attr_name_clean = WC_Bulk_Order_Form_Compatibility::wc_attribute_label($attr_name);
                     } else {
                         $np = explode("-", str_replace("attribute_", "", $attr_name));
                         $attr_name_clean = ucwords(implode(" ", $np));
                     }
                     $attr_name_clean = str_replace("attribute_pa_", "", $attr_name_clean);
                     $attr_name_clean = str_replace("Attribute_pa_", "", $attr_name_clean);
                     $title .= " - " . $attr_name_clean . ": " . $attr_value;
                 }
                 $title = html_entity_decode($title, ENT_COMPAT, 'UTF-8');
             }
             $parent_image = wp_get_attachment_image_src(get_post_thumbnail_id($id), 'thumbnail');
             $parent_image = $parent_image[0];
             $img = wp_get_attachment_image_src(get_post_thumbnail_id($parent->id), 'thumbnail');
             $img = $img[0];
             if (!empty($img)) {
                 $img = $img;
             } elseif (!empty($parent_image)) {
                 $img = $parent_image;
             } else {
                 $img = apply_filters('woocommerce_placeholder_img_src', WC_Bulk_Order_Form_Compatibility::WC()->plugin_url() . '/assets/images/placeholder.png');
             }
         }
         if ($hide_product == 'false') {
             $symbol = get_woocommerce_currency_symbol();
             $symbol = html_entity_decode($symbol, ENT_COMPAT, 'UTF-8');
             $price = html_entity_decode($price, ENT_COMPAT, 'UTF-8');
             // Initialise suggestion array
             $suggestion = array();
             $switch_data = isset($this->options['search_format']) ? $this->options['search_format'] : '1';
             $price = apply_filters('wc_bulk_order_form_price', $price, $product);
             switch ($switch_data) {
                 case 1:
                     if (!empty($sku)) {
                         $label = $sku . ' - ' . $title . ' - ' . $price;
                     } else {
                         $label = $title . ' - ' . $price;
                     }
                     break;
                 case 2:
                     if (!empty($sku)) {
                         $label = $title . ' - ' . $price . ' - ' . $sku;
                     } else {
                         $label = $title . ' - ' . $price;
                     }
                     break;
                 case 3:
                     $label = $title . ' - ' . $price;
                     break;
                 case 4:
                     if (!empty($sku)) {
                         $label = $title . ' - ' . $sku;
                     } else {
                         $label = $title;
                     }
                     break;
                 case 5:
                     $label = $title;
                     break;
             }
             $suggestion['label'] = apply_filters('wc_bulk_order_form_label', $label, $price, $title, $sku, $symbol);
             $suggestion['price'] = $price;
             $suggestion['symbol'] = $symbol;
             $suggestion['id'] = $id;
             $suggestion['imgsrc'] = $img;
             if (!empty($variation_id)) {
                 $suggestion['variation_id'] = $variation_id;
             }
             // Add suggestion to suggestions array
             $suggestions[] = $suggestion;
         }
     }
     // JSON encode and echo
     $response = $_GET["callback"] . "(" . json_encode($suggestions) . ")";
     //print_r($response);
     echo $response;
     // Don't forget to exit!
     exit;
 }