Add an action button to Woocommerce my account orders that open in a new window

Jeil

I'm going to add a button from my account order to make it go to a specific url. I made a button, but I want to open it with a new window instead of going to the page. What should I do? Down below is the code I added, and I'd like to open url here with a cage:

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 );

how to add target="_blank" to each additional custom button?

LoicTheAztec

Use the following that will add to each specific action html tag the attribute target with a _blank value opening the link in a new window:

// Your additional action button
add_filter( 'woocommerce_my_account_my_orders_actions', 'add_my_account_my_orders_custom_action', 10, 2 );
function add_my_account_my_orders_custom_action( $actions, $order ) {
    $action_slug = 'specific_name';

    $actions[$action_slug] = array(
        'url'  => home_url('/the_action_url/'),
        'name' => 'The Button Text',
    );
    return $actions;
}

// Jquery script
add_action( 'woocommerce_after_account_orders', 'action_after_account_orders_js');
function action_after_account_orders_js() {
    $action_slug = 'specific_name';
    ?>
    <script>
    jQuery(function($){
        $('a.<?php echo $action_slug; ?>').each( function(){
            $(this).attr('target','_blank');
        })
    });
    </script>
    <?php
}

Code goes in functions.php file of your active child theme (or active theme). Tested and works.

You will have to set the same unique and explicit $action_slug variable in both functions.


To target orders complete only, add if ( $order->has_status('completed') ) { in the first function only like:

add_filter( 'woocommerce_my_account_my_orders_actions', 'add_my_account_my_orders_custom_action', 10, 2 );
function add_my_account_my_orders_custom_action( $actions, $order ) {
    if ( $order->has_status( 'completed' ) ) {
        $action_slug = 'specific_name';

        $actions[$action_slug] = array(
            'url'  => home_url('/the_action_url/'),
        'name' => 'The Button Text',
        );
    }
    return $actions;
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Add an action button to WooCommerce "my account" orders according to product id

Add an action button with a unique CSS class to WooCommerce my account orders

Move an action button first in WooCommerce My account Orders page

Add "Pay for order" Button in WooCommerce My account Orders Custom Column

Change view button text in Woocommerce My account orders table

Conditional Cancel Button on my account orders list in Woocommerce

Remove cancel button from WooCommerce My account Orders conditionally

Show products name and quantity in a new column on Woocommerce My account Orders

Add a custom column to My Account Orders table in Woocommerce 3+

Add columns date created and order number to WooCommerce My account Orders

Add multiple custom columns to WooCommerce "My account" orders table

Add column total order weight to WooCommerce My account Orders

Change sorting of WooCommerce My account customer orders

Displays Woocommerce My Account Orders instead of Dashboard

Display latest orders on WooCommerce "My account" Dashboard

Create a Woocommerce My Account Orders page showing only Completed orders

How to show product name in a new column in WooCommerce "My account" orders table

WooCommerce: Add a birthdate billing field in checkout, My account, admin orders and WordPress user

Add Admin order notes sent to customer in WooCommerce My Account Orders list

How to add new Custom Title in Woocommerce My Account sidebar?

Add Cancel button on My account Orders list using Woo Cancel for Customers Plugin

Add a button on top of admin orders list in woocommerce

display product description in my account orders table of Woocommerce

Hide orders with status (Pending Payment) on WooCommerce My Account page

Display product thumbnails on WooCommerce My account orders list

Remove items count from my account orders table in Woocommerce

Customizing My Account Orders list post per page in Woocommerce

How to change column heading in WooCommerce "My account" orders table

Remove pagination on My account orders list to make it one page in woocommerce

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive