Skip to content

Instantly share code, notes, and snippets.

@Babylon1999
Last active August 15, 2024 13:38
Show Gist options
  • Save Babylon1999/3364e36fde2fb5423dab8ab9f0e842f9 to your computer and use it in GitHub Desktop.
Save Babylon1999/3364e36fde2fb5423dab8ab9f0e842f9 to your computer and use it in GitHub Desktop.
<?php
/**
* Plugin Name: WooCommerce Analytics - Custom Report Columns
* Description: This plugin adds a custom columns to the WooCommerce Analytics customer report csv export.
* Author: Saif Hassan
* Author URI: https://saif-hassan.com
* Version: 1.0.0
*/
/**
* Add hooks for report columns.
*/
function initialize_report_columns_plugin()
{
add_filter('woocommerce_report_customers_export_columns', 'get_report_export_columns');
add_filter('woocommerce_report_customers_prepare_export_item', 'prepare_export_item', 10, 2);
}
add_action('plugins_loaded', 'initialize_report_columns_plugin');
function get_report_export_columns($export_columns)
{
$export_columns['phone_number'] = 'Billing Phone';
return $export_columns;
}
function prepare_export_item($export_item)
{
// The user ID isn't within the exported items, thus using the username, it should work fine.
$user = get_user_by('login', $export_item['username']);
$export_item['phone_number'] = get_user_meta($user->ID, 'billing_phone', true) ? get_user_meta($user->ID, 'billing_phone', true) : "N/A";
return $export_item;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment