I added 4 new meta data fields to each order. I can update these fields myself for each order from within the admin panel but there are 200 orders and it will take awhile.
I need automatically populate these meta fields for each order. Future orders will automatically be populated but I need to update all orders at this time.
I wrote the following code but it doesn't do anything:
add_action( 'woocommerce_loaded', 'update_existing_orders_with_new_meta' );
function update_existing_orders_with_new_meta(){
$order_ids = wc_get_order( $order_id );
// Loop through product Ids
foreach ( $order_ids as $order_id ) {
if ( $order_id->payment_method == 'cheque' ) {
$order_id->update_meta_data('ji_payment_status', '');
$order_id->update_meta_data('ji_payment_method', '');
$order_id->update_meta_data('ji_payment_date', '');
$order_id->update_meta_data('ji_payment_notes', '');
} else {
$order_id->update_meta_data('ji_payment_status', '1');
$order_id->update_meta_data('ji_payment_method', 'Credit Card');
$order_id->update_meta_data('ji_payment_date', date('F j, Y'));
$order_id->update_meta_data('ji_payment_notes', '');
}
}
}
Can someone walk me through how to do that?