Add value to custom column on customer's orders page in woocommerce

Related searches

I was trying to add new column to the orders page of the customer's recent orders table, the new column should show the details of the product like product name & description.

Tried different solution, was fortunate to add column name but not able to add the value to the column.

Here is my code:

add_filter( 'woocommerce_account_orders_columns', 'new_orders_columns' );
function new_orders_columns( $columns = array() ) {
// Hide the columns
if( isset($columns['order-total']) ) {
    unset( $columns['order-status'] );
    unset( $columns['order-total'] );
    unset( $columns['order-actions'] );
}
// Add new columns
//this is my custom column order details
$columns['order-detail'] = __( 'Details', 'woocommerce' );
$columns['order-status'] = __( 'Status', 'woocommerce' );
$columns['order-total'] = __( 'Total', 'woocommerce' );
$columns['order-actions'] = __( ' ');

return $columns;
}

Screenshot of the result:

You are very near…

1) Insert a new column in a specific location (another way):

add_filter( 'woocommerce_account_orders_columns', 'add_custom_account_orders_column', 10, 1 );
function add_custom_account_orders_column( $columns ) {
    $ordered_columns = array();

    // Inserting a new column in a specific location
    $ordered_columns['order-number'] = $columns['order-number'];
    $ordered_columns['order-date'] = $columns['order-date'];
    $ordered_columns['order-details'] =  __( 'Details', 'woocommerce' ); // <== New column
    $ordered_columns['order-status'] = $columns['order-status'];
    $ordered_columns['order-total'] = $columns['order-total'];
    $ordered_columns['order-actions'] = $columns['order-actions'];

    return $ordered_columns;
}

Code goes in function.php file of your active child theme (or active theme).

tested and works.


2) Display data in this new column (editing myaccount/orders.php template):

You will need to override through your active child theme, the myaccount/orders.php WooCommerce template.

At line 56 (just after 'order-number' code) you will insert the following and you will be able to add some specific content:

<?php elseif ( 'order-details' === $column_id ) : ?>
     <?php 
         // HERE GOES YOUR CUSTOM CODE (DISPLAYED CONTENT)
     ?>

You can use the available WC_Order object $order


How to get WooCommerce order details

How to add columns to customer grid in Magento 2, These custom columns will render data from a custom joined table. with three simple steps to add another column to the Magento customer grid. call it magenest_custom_column with only two columns, id and value. From either the Contacts, Companies, or Deals page, choose +Add Column. Enter a column name and a type. You can choose from a text column, a number column, or a date column. Choose Add to save your custom field.

Accepted answer is only partially correct. Adding the column via filter is fine, but populating the column is better done via a action hook. This is clean and matches best with column being added via filter. While editing the orders.php page via child theme works, it will lead to future effort to maintain after updates to woocommerce change this page making child theme version out of date.

To add your content to the column create an action hook along side the filter in functions.php. (or better yet in a plugin!)

add_action( 'woocommerce_my_account_my_orders_column_order-detail' , 'your_function_name2',10,1 ); 
//'woocommerce_my_account_my_orders_column_<column_id>'
function your_function_name2( $order ) {

        // do stuff, ex: get_post_meta( $post->ID, 'key', true );

}

add_filter( 'woocommerce_account_orders_columns', 'new_orders_columns',10,1 );
function new_orders_columns( $columns) {

    // Add new column. Kept simple to play nice with other filters.
    $columns['order-detail'] = __( 'Details', 'woocommerce' );   

    return $columns;
}

see this similar question, best answer by Misha

How to add a custom column in customer table in Magento2?, I want to add a custom column(Telephone) in Customer table in magento2 and want to add value in this field while customer registration. For this first I create a� Hi for a custom column that Im building is there a way to set the value after a condition is satisfied. example, is the stock above the 50 day? so if the condition is true show the value in the column. i do not want to use the add label command and if i plot condition=true it only shows binary 0 or 1 value.

Try to use this code

<?php
// ------------------
// 1. Register new endpoint to use for My Account page
// Note: Resave Permalinks or it will give 404 error

function bbloomer_add_premium_support_endpoint() {
  add_rewrite_endpoint( 'premium-support', EP_ROOT | EP_PAGES );
}

add_action( 'init', 'bbloomer_add_premium_support_endpoint' );


// ------------------
// 2. Add new query var

function bbloomer_premium_support_query_vars( $vars ) {
  $vars[] = 'premium-support';
  return $vars;
}

add_filter( 'query_vars', 'bbloomer_premium_support_query_vars', 0 );


// ------------------
// 3. Insert the new endpoint into the My Account menu

function bbloomer_add_premium_support_link_my_account( $items ) {
  $items['premium-support'] = 'Premium Support';
  return $items;
}

add_filter( 'woocommerce_account_menu_items', 'bbloomer_add_premium_support_link_my_account' );


// ------------------
// 4. Add content to the new endpoint

function bbloomer_premium_support_content() {
  echo '<h3>Premium WooCommerce Support</h3><p>Welcome to the WooCommerce support area. As a premium customer, you can submit a ticket should you have any WooCommerce issues with your website, snippets or customization. <i>Please contact your theme/plugin developer for theme/plugin-related support.</i></p>';
  echo do_shortcode( ' /* your shortcode here */ ' );
}

add_action( 'woocommerce_account_premium-support_endpoint', 'bbloomer_premium_support_content' );

Magento 2 : How to Add New Column In The Customer Grid, How to Add New Column in Customer Grid in Magento 2 Last time we learned about How to Create a Custom Table via XML In Magento 2.3. Here, we are using the rendered to customize column value, so for achieving� User - requires an SPUser value. If you are able to retreive the login name of the user, do SPWeb.EnsureUser(" loginname ") and assign the value to your field. Else if you are getting the value from another User column, directly assign it to your user field.

How to add a custom column in customer grid in Magento 2 , In that situation, we have to add a custom column in the customer use Magento \Framework\View\Element\UiComponent\ContextInterface;. That's not possible. Outlook doesn't support the addition of custom icon-type columns in a view. You can, however, add a column to display the text, numeric or Boolean value associated with a UserProperty. Tuesday, August 3, 2010 11:56 AM

Adding a column to the customers grid in Magento admin, How to add column to Magento customers grid. Nick described the simple and trivial way of adding columns in his article Adding a custom attribute/column to the orders You should check out your value for this parameter. I want to add a custom column(Telephone) in Customer table in magento2 and want to add value in this field while customer registration. For this first I create a

It's very strange because this has worked before (I already added some custom columns. No idea how I can fix this. This is very important to start rolling out OCM in our company.

Comments
  • thanks nikita but I was looking to add the product details of the order to the newly created column(Details). @nikita