Developers

Overview

This documentation guides developers through integrating a custom code snippet into a WooCommerce site to add ‘Email Address’ and ‘Phone Number’ columns to the ‘Report by order details’ table.

Prerequisites

  • Basic knowledge of PHP and WordPress development.
  • Access to the site’s functions.php file or a suitable plugin for custom code snippets.
  • An operational WooCommerce environment.

Code Snippet

add_filter( 'sre_order_details_table_header', 'sre_order_details_table_header', 10, 1 );
function sre_order_details_table_header( $array ) {
     $array[] = 'Email Address';
     $array[] = 'Phone Number';
     return $array;
}

add_filter( 'sre_order_details_table_content', 'sre_order_details_table_content', 10, 2 );
function sre_order_details_table_content( $array, $order ) {
    $billing_email = $order->get_billing_email();
    $billing_phone = $order->get_billing_phone();
    $array[] = $billing_email;
    $array[] = $billing_phone;
    return $array;
}

Implementation Guide

  1. Backup Your Site: Ensure you have a recent backup of your site before modifying any code.
  2. Add the Code: Paste the provided snippet into the site’s functions.php file or a custom plugin for code snippets.
  3. Understanding the Code:
    • sre_order_details_table_header: Modifies the table header by adding ‘Email Address’ and ‘Phone Number’ columns.
    • sre_order_details_table_content: Fetches and adds the order’s billing email and phone number to the respective new columns in each order row.
  4. Test the Implementation: After adding the snippet, generate a report to ensure the new columns appear with the correct data.

Troubleshooting

  • Data Not Appearing: Confirm that the orders have billing emails and phone numbers associated with them.
  • Code Conflicts: If issues arise after adding the code, remove it to check if the problem persists. Consult a professional if necessary.

Caution

  • Modifying code directly can have unintended effects. Consider using a child theme or a custom plugin to avoid losing changes during updates.
  • Always test changes on a staging site first.

$99.00

Billed annually

Buy Now