Save user meta on Woocommerce EU VAT Plugin

I’m making a wordpress woocommerce run website which i’m building to store VAT Numbers, and make it so that a user and admin can edit it when needed.

I’m using the official woocommerce eu vat plugin – http://www.woothemes.com/products/eu-vat-number/ which stores the VAT number to the user meta. I’ve successfully used ACF to display this field in the backend and the front end of woocommerce, but i’m having trouble updating the user meta after checkout.

Read More

For example;

If the user had 12456 as a VAT number already stored, then went onto the checkout and decided they wanted to use another one, so they changed the field from 12456 to 999999 and then checked out, I want the plugin to update the stored VAT Number.

I’ve got this to work in the backend admin, but can’t get it to work at checkout.

The code i’ve used on the backend is

update_user_meta($user_id,'VAT Number', $_POST['VAT_Number']);

Related posts

Leave a Reply

1 comment

  1. add_action('woocommerce_checkout_update_user_meta', my_custom_checkout_field_update_user_meta');
    
    function my_custom_checkout_field_update_user_meta( $user_id ) {
        if ($user_id && $_POST['vat_number']) 
            update_user_meta( $user_id, 'vat_number', esc_attr($_POST['vat_number'])     
        );
    }