Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WooCommerce, add customer mail to the order admin list.
<?php
/*
Plugin Name: WooCommerce Overwrite Order Columns
Plugin URI:
Description: Adds the customers mailadress back to the order admin list.
Author: Mo
Version: 0.1
Author URI:
*/
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
/**
* Check if WooCommerce is active
**/
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) {
/**
* Add new content to the "order_number" column
* We use a priority of 11 to add the new content after the default content, so the default content is kept.
* After the default content we add the customer mail, as a clickable mailto link.
**/
add_action( 'manage_shop_order_posts_custom_column', 'wcooc_add_to_order_number', 11, 2 );
function wcooc_add_to_order_number( $column_name, $post_id ) {
// Get an instance of the WC_Order object
$order = wc_get_order( $post_id );
// Get the Order data
$order_data = $order->get_data();
// Get the billing mailadress from the order data
$order_billing_email = $order_data['billing']['email'];
// Add content to default column "order_number"
if ($column_name == 'order_number') {
echo '<a href="mailto:'.$order_billing_email.'" style="display:block;">'.$order_billing_email.'</a>';
}
}
}//END WC check
@bighippo999

This comment has been minimized.

Copy link

commented Mar 27, 2018

Thank you. This info should never have been removed from the orders screen. You've just made my day finding this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.