-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhpos-repair-v2.php
37 lines (32 loc) · 1.45 KB
/
hpos-repair-v2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
// Enable error reporting for testing.
error_reporting(E_ALL);
ini_set('display_errors', 1);
// First, add a filter to override the internal meta key check.
// This forces WooCommerce to allow generic meta updates for _billing_email.
add_filter( 'woocommerce_is_internal_meta_key', '__return_false' );
// List the affected order IDs (adjust the list as needed).
$affected_orders = [395, 403, 405, 417, 419];
foreach ( $affected_orders as $order_id ) {
// Get the order object.
$order = wc_get_order( $order_id );
if ( ! $order ) {
WP_CLI::warning("Order #$order_id not found.");
continue;
}
// Retrieve the billing email from the postmeta.
$billing_email = get_post_meta( $order_id, '_billing_email', true );
if ( empty( $billing_email ) ) {
WP_CLI::warning("Order #$order_id has an empty billing email. Skipping.");
continue;
}
// Use the dedicated setter to update the billing email.
// (WooCommerce provides set_billing_email() for this purpose.)
$order->set_billing_email( $billing_email );
// Save the order so that the new value is written into HPOS.
$order->save();
WP_CLI::success("Order #$order_id re-saved with billing email: $billing_email");
}
// Remove the temporary filter so that normal internal meta handling resumes.
remove_filter( 'woocommerce_is_internal_meta_key', '__return_false' );
WP_CLI::log("Test update complete. Please now run the verification command.");