wasted more than 12 hours for getting this to work, without luck. Found some other threads here, with some similar questions but all without a response.
// What i need?
I need a checkbox on WooCommerce Admin orders view to each product, if is checked
the value yes : no should be stored as order_item_meta
. So the customer can check, if all ordered items are shipped completely or not.
To hook in, the action woocommerce_after_order_itemmeta
looks like the correct position.
// Why not simply add Meta to item??
yeah right, it works - but wouldn't it be nice have a checkbox for this? :)
// What i have done so far??
reading a lot of postings in here, especially this one -> WooCommerce-admin-order-details-show-custom-data-on-order-details-page.
I have no clue, where and how i could start with this - ended up with this peace of code in my functions.php..
<?php
add_action( 'woocommerce_after_order_itemmeta', 'item_shipped',
10, 3 );
function item_shipped() {
?>
<input type="checkbox" name="custom-meta-box[]" value="yes" <?php if(isset($_POST['is-shipped-meta']['is_shipped'])) echo 'checked="checked"'; ?> /> is shipped?
<?php
}
add_action( 'woocommerce_add_order_item_meta', 'save_is_shipped_meta' );
function save_is_shipped_meta()
{
global $item_id, $item, $product;
// Get our form field
if(isset( $_POST['is-shipped-meta'] ))
{
$value = $_POST['is-shipped-meta'];
$old_meta = get_metadata($item->id, 'is-shipped-meta', true);
// Update order item meta
if(!empty($old_meta)){
woocommerce_add_order_item_meta($item->id, 'is-shipped-meta', $value);
} else {
woocommerce_add_order_item_meta($item->id, 'is-shipped-meta', $value);
}
}
}
?>
On frontend, my-account actually looks like this. Frontend - My Account With the green dot as indicator, the customers can check if the ordered item is already shipped!
Any Idea, how i can get this to work?
I really appreciate for your time and help. Thanks!