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 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;
}