You can easily add action buttons to the WooCommerce My Orders table in the customer’s My Account section of your site. The default buttons include actions like “Pay”, “Cancel”, and “View”, but you can add your own actions for each order.

The woocommerce_my_account_my_orders_actions filter makes it very simple to add our actions. Actions are an array, so you add your own action into the array and then give them back to WooCommerce. The filter gives you the actions, as well as the order, so that you can check for things like order status or order number to use in your action or conditionally add it (as the “Pay” action does).

The basic format to add an action looks like this:

function sv_add_my_account_order_actions( $actions, $order ) {

    $actions['name'] = array(
        'url'  => 'the_action_url',
        'name' => 'The Button Text',
    );
    return $actions;
}
add_filter( 'woocommerce_my_account_my_orders_actions', 'sv_add_my_account_order_actions', 10, 2 );

You can add as many actions as you like by duplicating the $actions['key'] = array(); part, and these actions can be conditionally added based on the order data if desired.

Let’s go through a sample use case to add an action for all orders.

Add a “Get Help” Action for My Orders

Here’s a sample use case: let’s say that you want to let customers easily get help with an order and reach out to you. You could use a generic URL for all orders, such as mysite.com/contact/, but you probably want to know what order the customer needs help with.

We use this ourselves in conjunction with Gravity Forms. We pass the order number into the URL, and use Gravity Form’s ability to dynamically populate a form field to pre-fill the order number. This lets us gather the order number when customers submit the form without any effort in their part, making it as simple as possible for them to get in touch.

Gravity Forms Dynamic Populate

Enable dynamic population

We’ll need to enter the URL of our contact form, and pass in the order number along with it.

function sv_add_my_account_order_actions( $actions, $order ) {

    $actions['help'] = array(
        // adjust URL as needed
        'url'  => '/contact/?&order=' . $order->get_order_number(),
        'name' => __( 'Get Help', 'my-textdomain' ),
    );

    return $actions;
}
add_filter( 'woocommerce_my_account_my_orders_actions', 'sv_add_my_account_order_actions', 10, 2 );

This adds our “Get Help” action to every order in the WooCommerce My Orders table.

WooCommerce order action

New action added

When the customer clicks that action for a particular order, they’ll be taken to the page with our form, and our field for order number will already be populated. The order number will change depending on which “Get Help” button is clicked in order to use the order number for that row.

WooCommerce get help form

Order Number pre-filled

To take this further, you could add “Get Help” buttons only if the order isn’t completed, add a “Request Refund” button only if it’s completed, or add all sort of other conditional actions to help your customers.

Published by Beka Rice

Beka leads product direction for SkyVerge, focusing on new features for our plugins and Jilt. She spends a lot of time on research and interviews, but likes to write so she has an excuse to spend more time jamming out to anything from The Clash to Lady Gaga.

12 Comments

  1. Hi Beka, thanks for your useful post.
    Sorry for the question: is it possible to use cf7 in some way in order to get that ‘order’ case?
    Consider that cf7 plugin is considerably included mostly in the majority of wordpress premium themes, instead of gravity one.
    Or better, is there a workaround to get order number without gravity forms?
    Thanks in advance for your help 😉

    • I don’t think Contact Form 7 lets you dynamically populate fields, so I don’t think you could use it to create something like this unfortunately. Worth pinging their team about though, as I don’t use it so I could be wrong.

  2. […] a WooCommerce tutorial from SkyVerge on adding action buttons to the WooCommerce “My Orders” […]

  3. Hey Beka,

    Thanks for posting all these neat tutorials! I’m constantly checking the site for any new tips/tricks. 🙂

    Do you guys have any tips for adding a “Description” column to the My Orders Table; ideally that shows the products purchased so that customers don’t have to click the Order ID?

    Cheers,
    ~ Amber

    • Hey Amber, glad it’s been useful 🙂 Unfortunately there aren’t really hooks in that template to add columns, but you could override it to add a new column; since you have the $order already, you could use $order->get_items() to get the products in it.

    • You can take inspirations from this I used in the past: http://pastebin.com/hPiMsW1n

      You need to overload the my-orders.php template and edit this file in the order cycle.

  4. Where do I place this code? functions.php ?

  5. Hi,

    Thank ypu for this great tutorial.
    Could you please tel me how we can replace the buton for icon in the account order table?
    I’ll like to use font awsome instead of the buttons

    Thank you in advance
    Fred

  6. Hi Beka,

    I’ve used the Checkout Manager plug-in to add a few custom checkout fields and wondering if I can produce a list of orders that has the custom field ‘auto_delivery’ = 1? (since the custom field is a check box).

    I want to also show this either on the My Orders page or a new page that I have created.

    So I guess the following query condition clauses are:

    order->user_id = wp_get_user->user_id AND
    order->auto_delivery = 1

    Thanks
    Stan

  7. Hi’ Beka

    How would i populate more than one field…??? Let’s say i want to fill in the name field automatically through Gravity forms along wih the order number. Could this be done in any way….???

    Thank You in advance,
    Carsten

    • Yep, you could use an & between the two fields — check out this URL which fills in our first two contact form fields.

      However, if you want to use user information, the easier way is to use the “default values” for the form, and setting your name field to the user display name:

  8. Hi’ Beka

    Thanks. It is working. I used the default values for the form. However, i have another issue. I need to populate another field with the total price from the order. How should i alter the code in order to achieve this:

    I know that using $order->get_total() gets me the total price but how do i incorporate it in the above code so i get both order number and total price populated in to different fields in the form.

    Thanks i advance.

    Carsten

Hmm, looks like this article is quite old! Its content may be outdated, so comments are now closed.