Skip to content

Instantly share code, notes, and snippets.

@kilbot
Last active February 15, 2022 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kilbot/51dafedbf0fea3781ec547ab227d0b34 to your computer and use it in GitHub Desktop.
Save kilbot/51dafedbf0fea3781ec547ab227d0b34 to your computer and use it in GitHub Desktop.
Snippet to update order postmeta
<?php
global $wpdb;
$customer_id = 6; // CHANGE THIS!
$customer_email = 'test@wordpress.com'; // CHANGE THIS!
$postids = $wpdb->get_col(
$wpdb->prepare(
"
SELECT pm.post_id
FROM {$wpdb->postmeta} pm
JOIN {$wpdb->posts} p
ON p.ID = pm.post_id
WHERE p.post_type = 'shop_order'
AND pm.meta_key = '_customer_user'
AND pm.meta_value = 0
"
)
);
if ( $postids ) {
foreach ( $postids as $id ) {
update_post_meta( intval( $id ), '_customer_user', $customer_id );
update_post_meta( intval( $id ), '_billing_email', $customer_email );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment