php - WooCommerce Admin -> Orders | add checkbox on each product -
wasted more 12 hours getting work, without luck. found other threads here, similar questions without response.
// need?
i need checkbox on woocommerce admin orders view each product, if checked
value yes : no should stored order_item_meta
. customer can check, if ordered items shipped or not. hook in, action woocommerce_after_order_itemmeta
looks correct position.
// why not add meta item??
yeah right, works - wouldn't nice have checkbox this? :)
// have done far??
reading lot of postings in here, 1 -> woocommerce-admin-order-details-show-custom-data-on-order-details-page.
i have no clue, , how start - ended peace of code in 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"'; ?> /> shipped? <?php } add_action( 'woocommerce_add_order_item_meta', 'save_is_shipped_meta' ); function save_is_shipped_meta() { global $item_id, $item, $product; // 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 looks this. frontend - account green dot indicator, customers can check if ordered item shipped!
any idea, how can work?
i appreciate time , help. thanks!
Comments
Post a Comment