Halloween Sale 15% off Ends in See the plans
PHP

Customer Email and Phone Column in the Orders List

Adds the customer's email address and phone number to the admin orders list as click-to-email and click-to-call links.

Don’t have WPIDE yet? Install it on your site

Code

$wpide_contact_column = function ( $columns ) {
    $columns['wpide_contact'] = 'Contact';

    return $columns;
};

$wpide_contact_render = function ( $column, $order ) {
    if ( 'wpide_contact' !== $column ) {
        return;
    }

    $order = $order instanceof WC_Order ? $order : wc_get_order( $order );

    if ( ! $order ) {
        return;
    }

    $email = $order->get_billing_email();
    $phone = $order->get_billing_phone();

    if ( $email ) {
        printf( '<a href="mailto:%1$s">%2$s</a><br>', esc_attr( $email ), esc_html( $email ) );
    }

    if ( $phone ) {
        printf( '<a href="tel:%1$s">%2$s</a>', esc_attr( preg_replace( '/[^\d+]/', '', $phone ) ), esc_html( $phone ) );
    }
};

add_filter( 'manage_woocommerce_page_wc-orders_columns', $wpide_contact_column );
add_filter( 'manage_edit-shop_order_columns', $wpide_contact_column );
add_action( 'manage_woocommerce_page_wc-orders_custom_column', $wpide_contact_render, 10, 2 );
add_action( 'manage_shop_order_posts_custom_column', $wpide_contact_render, 10, 2 );

Notes

Only staff who can view the orders screen see these details.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.