0

I have added an action button to the orders page and I want it to open in a new window. This is my code:

 if ( $order->has_status( array( 'processing' ) ) ) {

        // Get Order ID (compatibility all WC versions)
        $order_id = method_exists( $order, 'get_id' ) ? $order->get_id() : $order->id;
        // Set the action button
        $actions['parcial'] = array(
        'url'       => wp_nonce_url( str_replace("https://","",plugins_url( 'generate_label.php', __FILE__ ) . '?text=' . $order_id), 'woocommerce-mark-order-status' ),
        'name'      => __( 'Print Labels', 'woocommerce' ),
        'target'    => '_blank',
        'action'    => "view parcial", // keep "view" class for a clean button CSS
        );    
}

What do I need to add in order to accomplish it?

0

You would need to override the /myaccount/my-orders.php template file.

Using your code to add 'target' => '_blank' to $actions['parcial'], I would edit this part of the template to look something like this:

$actions = wc_get_account_orders_actions( $order );

if ( ! empty( $actions ) ) {
    foreach ( $actions as $key => $action ) {
        echo '<a href="' . esc_url( $action['url'] ) . '" class="button ' . sanitize_html_class( $key ) . '" target="' . esc_html( $action['target'] ) '>' . esc_html( $action['name'] ) . '</a>';
    }
}

You can find info on overriding WooCommerce template files here: Template structure & Overriding templates

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.