Retrieve menu order of item
-
I’m selling tons of tiny items. In my functions.php I have some code to provide my order overview with a column that displays how many purchased items and how many lots (unique products) are in each order.
However, I’m storing my inventory in two separate rooms and I would like this column to display not just how many unique products are in it, but how many unique products in room 1 and how many in room 2. This would help A LOT in my picking routine.
The location of each product depends on its menu order. Say that all items up to menu order 1000 are in room 1, and all items with a menu order number >1000 are in room 2. How do I retrieve the menu order in code for my functions.php to do this? Once I know how to retrieve it, I think I’ve got it from there (if-statement, then add +1 to either a room1 or room2 variable).
add_filter( 'manage_edit-shop_order_columns', 'woo_order_itemslots_column' ); function woo_order_itemslots_column( $columns ) { $columns['total_itemslots'] = __( 'Items (Lots)', 'woocommerce' ); return $columns; } add_action( 'manage_shop_order_posts_custom_column', 'woo_custom_order_itemslots_column', 2 ); function woo_custom_order_itemslots_column( $column ) { global $post, $woocommerce, $the_order; if ( empty( $the_order ) || $the_order->id != $post->ID ) $the_order = new WC_Order( $post->ID ); if ( $column == 'total_itemslots' ) { $lots= 0; $items= 0; if ( sizeof( $the_order->get_items() ) > 0 ) { foreach( $the_order->get_items() as $item ) { if ( $item['product_id'] > 0 ) { $_product = $the_order->get_product_from_item( $item ); if ( ! $_product->is_virtual() ) { $items += $item['qty']; $lots += 1; } } } } if ( $lots > 0 ) print $items . ' (' . $lots . ')'; else print 'N/A'; } }
TLDR: I’d like to retrieve the menu order of a product in code.
- The topic ‘Retrieve menu order of item’ is closed to new replies.