Popular Categories
How to extend admin fields in WooCommerce orders page?
Sometimes you need to further extend the Admin Listing. For instance in the current problem i needed to add the serial numbers to the WooCommerce orders listing.
1. edit_shop_order_columns
is the function where i am rearranging the fields
2. shop_order_column
is the function where i am managing those fields and providing the values respectively.
add_filter( 'manage_edit-shop_order_columns', 'edit_shop_order_columns' ) ; function edit_shop_order_columns( $columns ) { $columns = array( 'cb' => '<input type="checkbox" />', 'order_number' => __( 'Order' ), 'order_date' => __( 'Order Date' ), 'order_status' => __( 'Status' ), 'serial' => __( 'Serial Number' ), 'order_total' => __( 'Order Total'), ); return $columns; } add_action( 'manage_shop_order_posts_custom_column', 'shop_order_column', 10, 2); function shop_order_column( $column, $post_id ) { global $post; $arr = ""; if ( 'serial' === $column ) { echo get_field('order_serial_number',$post_id); } } add_filter( 'manage_edit-serialnumber_columns', 'edit_serialnumber_columns' ) ; function edit_serialnumber_columns( $columns ) { $columns = array( 'cb' => '<input type="checkbox" />', 'title' => __( 'Serial Numner' ), 'products' => __( 'Linked Products' ), 'SKU' => __( 'SKU' ), 'status' => __( 'Status'), 'date' => __( 'Added Date' ) ); return $columns; } add_action( 'manage_serialnumber_posts_custom_column', 'realestate_column', 10, 2); function realestate_column( $column, $post_id ) { global $post; $arr = ""; if ( 'products' === $column ) { $productlist = get_field('products',$post_id); foreach($productlist as $row) { $arr[] = get_the_title($row); } echo implode(",",$arr); } $sku = ""; if ( 'SKU' === $column ) { $productlist = get_field('products',$post_id); foreach($productlist as $row) { $product = wc_get_product( $row ); echo $row; $sku[] = $product->get_sku(); } echo implode(",",$sku); } if ( 'status' === $column ) { echo get_field('available',$post_id); } }