I have a field CIF in my Woocommerce, I have 1000 orders with this field complete. This field shows because I used a plugin. ID Field is billing_cifnif.
Now I need to change this plugin for other plugin and I need that old field to be duplicated in a new field ID billing_nif.
I need to fill these 1000 orders with the new value.
I have this code:
add_action('woocommerce_thankyou', 'replicate_billing_email', 100, 1);
function replicate_billing_email($order_id){
$order = new WC_Order($order_id);
$billing_cifnif = $order->get_billing_cifnif();
update_post_meta($order_id, 'billing_nif', $billing_cifnif);
update_post_meta($order_id, '_billing_nif', $billing_cifnif);
}
It only works for new orders, I need to use it for the old orders.
Thank you
If you want to update your existing orders, then run the following snippet ONCE. After it's done running, delete it from the
functions.phpfile:NOTE:
functions.phpfile and remove the script!billing_nifand_billing_nif, so I included both! Please feel free to exclude/delete any of them as you see fit!