1

How do I either replace or completely remove a column in the Woocommerce Orders list in admin?

I know that there's possible to just uncheck the "Shipping address" column from the "Screen Options" and add another custom column and name it "Shipping address" too. But idealy I would like to just have one "Shipping address" column option and just be able to change what's in that column.

I have tried to first just remove the "Shipping address" column but isn't succeeding with that either:

function new_orders_columns($columns)
{
    unset($columns['shippging_address']);

    return $columns;
}

function after_woo()
{
    add_filter('manage_shop_order_posts_columns', 'new_orders_columns', 10, 1);
}

add_action('plugins_loaded', 'after_woo');

It just won't be removed. I have tried to change the priority and init/loaded hooks. But nothing works.

Any help here?

1

The correct filter hook to be used is manage_edit-shop_order_columns.

1) To remove shipping_address column:

add_filter( 'manage_edit-shop_order_columns', 'remove_specific_orders_column' );
function remove_specific_orders_column( $columns ){
    unset( $columns['shipping_address'] );

    return $new_columns;
}

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


2) Replace the content of shipping_address column:

Here is an example that will replace the column "Shipping address" content from Admin Orders list:

add_filter( 'manage_edit-shop_order_columns', 'customizing_orders_columns' );
function customizing_orders_columns( $columns ){
    $new_columns = [];

    foreach ( $columns as $key => $column ) {
        if( $key === 'shipping_address' ) {
            $new_columns['shipping_addr_repl'] = $column;
        } else {
            $new_columns[$key] = $column;
        }
    }
    return $new_columns;
}

add_action( 'manage_shop_order_posts_custom_column', 'set_custom_shipping_address_content_replacement' );
function set_custom_shipping_address_content_replacement( $column ) {
    global $the_order, $post;

    if ( 'shipping_addr_repl' === $column ) {
        // YOUR REPLACEMENT CODE (Fake example below)
        echo $the_order->get_shipping_city();
    }
}

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

enter image description here


The original displayed content code for this column is:

$address = $the_order->get_formatted_shipping_address();

if ( $address ) {
    echo '<a target="_blank" href="' . esc_url( $the_order->get_shipping_address_map_url() ) . '">' . esc_html( preg_replace( '#<br\s*/?>#i', ', ', $address ) ) . '</a>';
    if ( $the_order->get_shipping_method() ) {
        /* translators: %s: shipping method */
        echo '<span class="description">' . sprintf( __( 'via %s', 'woocommerce' ), esc_html( $the_order->get_shipping_method() ) ) . '</span>'; // WPCS: XSS ok.
    }
} else {
    echo '&ndash;';
}
  • Yes! I think I mixed up the hook names too when I was trying. This example worked great. Thanks – Peter Westerlund May 21 at 20:31
  • @PeterWesterlund Thanks… You could please add back the "php" tag in your question as this is related to php and not only woocommerce hooks (and may be the "functions" tag too). – LoicTheAztec May 21 at 21:01

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.