0

I am trying to change the columns in the orders overview (orders.php) in the Woocommerce My Account page. I got this working now but now it is changed in the quotes overview (quotes.php) as well.

Any ideas how to change the columns only in the orders overview?

This is what I did so far and what works well for the orders overview.

In the functions.php

add_filter( 'woocommerce_account_orders_columns', 'new_orders_columns' );
function new_orders_columns( $columns = array() ) {

        // Unsets the columns which you want to hide
        unset( $columns['order-total'] );
                unset( $columns['order-number'] );
                unset( $columns['order-date'] );
                unset( $columns['order-status'] );
                unset( $columns['order-total'] );
                unset( $columns['order-actions'] );


    // Add new columns
        $columns['rechnungsnummer'] = __( 'Rechnung', 'woocommerce' );
        $columns['order-date'] = __( 'Rechnungsdatum', 'woocommerce' );
        $columns['order-status'] = __( 'Status', 'woocommerce' );
        $columns['lieferdatum'] = __( 'Voraussichtliches Lieferdatum', 'woocommerce' );
    $columns['tracking'] = __( 'Tracking', 'woocommerce' );

    return $columns;

}

In the orders.php

<?php elseif ( 'tracking' === $column_id ) : ?>
            <?php
            $sendungsverfolgung_custom_field = get_post_meta($order->get_id(), 'rechnung_link', true);
            if ($sendungsverfolgung_custom_field == true) {
                echo '<a href="' . esc_html( get_post_meta($order->get_id(), 'rechnung_link', true)) . '" class="woocommerce-button button" target="_blank">Sendung verfolgen</a>';
                    } else {
                      echo "Folgt in Kürze";
                            }
                        ?>

<?php elseif ( 'rechnungsnummer' === $column_id ) : ?>
            <?php
            echo esc_html( get_post_meta($order->get_id(), 'rechnungsnummer', true));
            ?>

<?php elseif ( 'lieferdatum' === $column_id ) : ?>
            <?php
            echo esc_html( get_post_meta($order->get_id(), 'lieferdatum', true));
            ?>
Jorn
  • 1
  • 2
  • Not sure in what context the `quotes.php` gets shown/used, but perhaps you can use one of the conditional tags to differentiate between the two places/situations ...? https://woocommerce.com/document/conditional-tags/ – CBroe Feb 16 '22 at 08:21
  • Thanks. I tried to use conditional tags in the functions code. But I always get an error, no matter what condition I choose: `Parse error: syntax error, unexpected 'unset' (T_UNSET) in`-- PS: The quotes.php shows also a list of orders but with the status of a request that has not been purchased. – Jorn Feb 17 '22 at 13:36
  • Then you should go check [PHP parse/syntax errors; and how to solve them](https://stackoverflow.com/q/18050071/1427878). – CBroe Feb 17 '22 at 16:05
  • OK got it now. the error was in the conditions. I used `is_wc_endpoint_url( 'orders' )` – Jorn Feb 18 '22 at 18:14

0 Answers0