最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Woocommerce: Add column to ORDERS admin page with items purchased

programmeradmin9浏览0评论

After updating to Woocommerce 3.0, in the Woocommerce ORDER page (where you can check all the orders made by customers, with order status, billing address, shipping address, total, etc.) is missing the column with the items purchased by the customer. Before WC update, that column was there. Now it is gone.

Could anyone help me to add again this column?

Thanks a lot!

After updating to Woocommerce 3.0, in the Woocommerce ORDER page (where you can check all the orders made by customers, with order status, billing address, shipping address, total, etc.) is missing the column with the items purchased by the customer. Before WC update, that column was there. Now it is gone.

Could anyone help me to add again this column?

Thanks a lot!

Share Improve this question asked Apr 20, 2017 at 21:46 SenderSender 311 silver badge3 bronze badges 2
  • Here is a free plugin that restores it to just like it was before: wordpress/plugins/restore-purchased-items-column – anon Commented Apr 28, 2017 at 3:59
  • wordpress.stackexchange/a/336355/174108 how can add a category or tag or products thank you – MajidoRc Commented Aug 26, 2019 at 7:52
Add a comment  | 

3 Answers 3

Reset to default 1

I have already manage to create a column thanks to this:

    // ADDING COLUMN TITLES
add_filter( 'manage_edit-shop_order_columns', 'custom_shop_order_column',11);
function custom_shop_order_column($columns)
{
   //add columns
    $columns['my-column1'] = __( 'Column Title','theme_slug');
   return $columns;
}

// adding the data for each orders by column (example)
add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 10, 2 );
function custom_orders_list_column_content( $column )
{
    global $post, $woocommerce, $the_order;
    $order_id = $the_order->id;

    switch ( $column )
    {
        case 'my-column1' :
            $myVarOne = wc_get_order_item_meta( $order_id, '_the_meta_key1', true );
            echo $myVarOne;
            break;
    }

But I don't know how to add the data to this columns. I need to add the items purchased by the customers. Is it possible?

Thanks!

I use this to add an Ordered Products column right after the Date column (fits nicely there). Each product is also linked to it's proper edit page.

// ----- add column to orders that shows which products were ordered -----
function ec_order_items_column($columns) {
    $new_columns = array();
    foreach($columns as $key=>$column){
        $new_columns[$key] = $columns[$key];
        if($key === 'order_date') {
            $new_columns['ordered_products'] = __('Ordered Products','woo-custom-ec');
        }
    }
    return $new_columns;

    //$columns['order_products'] = "Purchased Items";
    //return $columns;
}
add_filter('manage_edit-shop_order_columns', 'ec_order_items_column', 99 );

// ----- add data to new column that shows which products were ordered -----
function ec_order_items_column_cnt($column) {
    global $the_order; // the global order object
    if($column == 'ordered_products') {
        // get items from the order global object
        $order_items = $the_order->get_items();
        if (!is_wp_error($order_items)) {
            foreach($order_items as $order_item) {
                echo $order_item['quantity'].'&nbsp;&times;&nbsp;<a href="'.admin_url('post.php?post='.$order_item['product_id'].'&action=edit' ).'">'.$order_item['name'].'</a><br />';
            }
        }
    }
}
add_action('manage_shop_order_posts_custom_column', 'ec_order_items_column_cnt', 99);

If you want to display the purchased products in a column, you can use this code:

add_action( 'manage_shop_order_posts_custom_column' , 'custom_orders_list_column_content', 10, 2 );
function custom_orders_list_column_content( $column )
{
    global $the_order;
    $order_id = $the_order->id;

    switch ( $column )
    {
        case 'my-column1' :
            $order_items = $the_order->get_items();
            foreach( $order_items as $myVarOne ) {
                echo $myVarOne['quantity'] .'&nbsp;&times;&nbsp;'. $myVarOne['name'] .'<br />';
            }
            break;
    }
}

You can also view the complete code with screenshots in this tutorial.

发布评论

评论列表(0)

  1. 暂无评论