How to generate dynamic “before and after” change reports in WordPress CSV imports

When running large product imports in WordPress—especially with custom tools or PIM integrations—it’s critical to understand exactly what changed. However, many import systems generate reports that are either too vague or overloaded with unnecessary data.

In this guide, we’ll walk through how to improve CSV import reporting by generating dynamic “before and after” change logs that only show meaningful updates.

Issue Background

A custom WordPress product importer generated a CSV report after each import, but it had several limitations:

  • It displayed only a limited set of predefined fields
  • It showed a generic “Set” value rather than actual before/after values
  • It included fields even when no changes occurred
  • The report became difficult to read and analyze

This made it difficult to validate import accuracy and debug product updates.

Diagnosis

1. Static field selection

  • The report used predefined fields regardless of whether changes occurred

2. Missing before-and-after comparison

  • The report did not display previous vs updated values

3. Excessive noise

  • Unchanged fields cluttered the report

4. No filtering for meaningful updates

  • Rows and columns were included even when no changes occurred

Resolution Steps

Step 1: Capture before and after values

$before = get_post_meta($product_id, $meta_key, true);
update_post_meta($product_id, $meta_key, $new_value);
$after = $new_value;

Step 2: Track only changed fields

if ($before !== $after) {
    $changes[$meta_key] = [
        'before' => $before,
        'after'  => $after
    ];
}

Step 3: Generate dynamic columns

  • Create columns only for fields that changed
  • Use field_before and field_after structure

Step 4: Exclude unchanged rows

  • Skip products with no detected changes

Step 5: Optional full reporting mode

  • Include all fields if needed, but be mindful of file size

Step 6: Test with varied datasets

  • Validate with pricing, inventory, and metadata changes

Final Outcome

  • Reports show true before-and-after values
  • Only changed fields are included
  • Unchanged rows are removed
  • Reports are easier to read and debug

If you’re working with WordPress imports, WooCommerce product data, or custom PIM integrations, our team can help build scalable solutions tailored to your workflow.

Contact Freshy