Mahesh Thorat
Mahesh Thorat

Reputation: 1

Add custom text to WooCommerce My account Orders inside the Action column

I tried using the code below to add custom text to WooCommerce My account Orders inside the Action column:

add_action('woocommerce_my_account_my_orders_column_order-actions', 'add_account_orders_column_rows');
function add_account_orders_column_rows($order)
{
   echo "TEST";
}

But it replace the default action buttons functionality, with my custom text, like:

enter image description here

I would like to keep the action buttons and my custom text.

How can we achieve this?

Upvotes: 1

Views: 140

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 254363

You missed adding some code to output action buttons, as the hook you are using in your code, replace the action buttons on the template myaccount/orders.php.

Try the following revisited code:

add_action('woocommerce_my_account_my_orders_column_order-actions', 'my_account_my_orders_column_order_actions_additional_content');
function my_account_my_orders_column_order_actions_additional_content( $order ) {
    $actions   = wc_get_account_orders_actions( $order );
    $btn_class = wc_wp_theme_get_element_class_name( 'button' ) ? ' ' . wc_wp_theme_get_element_class_name( 'button' ) : '';

    if ( ! empty( $actions ) ) {
        foreach ( $actions as $key => $action ) { // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited
            /* translators: %s: order number */
            echo '<a href="' . esc_url( $action['url'] ) . '" class="woocommerce-button' . esc_attr( $btn_class ) . ' button ' . sanitize_html_class( $key ) . '" aria-label="' . esc_attr( sprintf( __( 'View order number %s', 'woocommerce' ), $order->get_order_number() ) ) . '">' . esc_html( $action['name'] ) . '</a>';
        }
    }

    // Your content
    echo "TEST";
}

You will get something like:

WooCommerce My account orders

Related:

Upvotes: 1

Related Questions