0

I'm looking to add a custom link to the order table in /my-account/orders/ page in WordPress.

enter image description here

I want to add a column next to the "Actions" column and custom link to respective orders. Note, there can be multiple orders. I want to have the link for all orders.

I tried looking on SO but no luck. If this question has been asked previously then please share the link.

Akash Agrawal
  • 2,219
  • 1
  • 17
  • 38

1 Answers1

1

Use those two filters:

  • woocommerce_my_account_my_orders_columns
  • woocommerce_my_account_my_orders_column_{column_name}

For example:

<?php

function add_custom_link_to_my_account_orders_column( $columns ) {

    $new_columns = array();

    foreach ( $columns as $key => $name ) {

        $new_columns[ $key ] = $name;

        // add custom link column after total column
        if ( 'order-total' === $key ) {
            $new_columns['order-custom-link'] = __( 'Custom link', 'textdomain' );
        }
    }

    return $new_columns;
} 
add_filter( 'woocommerce_my_account_my_orders_columns', 'add_custom_link_to_my_account_orders_column' );


function add_link_to_custom_column( $order ) {
    // apply the logic here
    echo '<a href="#">Link</a>';
} 
add_action( 'woocommerce_my_account_my_orders_column_order-custom-link', 'add_link_to_custom_column' );
LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
brynzovskii
  • 355
  • 4
  • 13