Last active
February 15, 2022 22:31
-
-
Save kilbot/51dafedbf0fea3781ec547ab227d0b34 to your computer and use it in GitHub Desktop.
Snippet to update order postmeta
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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