6

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!

click here
  • 96
  • 1
  • 7
  • Do you need this status for every item or for the order as a whole? If the latter, you could try a custom order status. – helgatheviking Feb 08 '16 at 05:21
  • @helgatheviking thanks for your response! Actually, i trigger the green dot and mark all line items as shipped with the order status `completed` this works as long as the whole order is really shipped completely. If anyone need to know `get_status() ); if ($order_state == 'completed') { echo 'hooray';} ?>` So, it would be "perfect" if i could mark on the admin backend every line-item as shipped order not. – click here Feb 08 '16 at 09:05
  • Never mind, solved this problem by myself! – click here Feb 10 '16 at 17:22
  • whoops, pressing enter send the comment ;) 1. add order_item_meta ( is_shipped) ( functions.php / child-theme ) 2. set meta value to "false" ( functions.php / child-theme ) 3. add checkbox to each order item ( functions.php / child-theme ) 4. Traversing the input with jQuery & manipulate the textarea-field from meta "is_shipped" ( functions.php / child-theme + register .js ) 5. safe the form with woocommerce included ajax Yep, its a bit dirty, but the only way with my little bit of "skills" to solve this function. – click here Feb 10 '16 at 17:28
  • 1
    Great. It's a neat question, but more than I can look at for the moment. Got paying work that needs doing. :) – helgatheviking Feb 10 '16 at 18:06
  • @Juergen W – can you please post the full answer to your own question? – dj.cowan Nov 09 '18 at 23:52

0 Answers0