During the checkout process in WooCommerce I have removed many of the default fields to make sign up faster. Since my course is digital I don’t ask for shipping details and the only billing details I ask for is the country and the VAT Code (using this plugin) along with email and password, which is necessary for access to courses.
The problem with this is that when people want to download an invoice it will not have some of the information they may need.
I thought that if a user was able to update their address in their My Account area then the order billing details would also be updated as well. This is not the case.
Billing (and shipping) details are stored in the post meta for WooCommerce orders. This means that we have to hook in when a user saves their address and update the post meta for all of their orders as well.
First I want to say that this is a solution / hack for a very specific problem I have and it is not without consequences. This solution will update all orders for a custom whenever their save their billing details. I am fine with this, but your user may not expect this so proceed if this trade off is acceptable for you.
Here is what this code does:
- Hooks into the woocommerce_customer_save_address action hook.
- woocommerce_customer_save_address gives us access to customer user ID
- Then we get the meta data for the customer using get_user_meta(). This includes the updated billing details that were just saved.
- Following that we pull in all of the orders for that customer using get_posts()
- From there we loop through all the orders and update the order meta data to match the newly saved customer data.
I want to say again that a WooCommerce users post meta data for a reason. Just because a user updates their billing information does not mean that they want their past billing details replaced for orders already placed.
This was a bit of a quick hack and I am sure folks could make this more efficient. Please share if you have ideas or found this useful!
However, this allows me to simplify my checkout process and give customers an easy way to add whatever information they need in their invoices then download them.