I've got the following code which updates a VAT Numebr which is stored against the user meta. I was wondering if anyone knew how I could add Woocommerce Success message which says something along the lines of 'VAT Number Successfully Updated' once the form has been submitted and the page has refrwshed. With my current code, it works but the message only appears once I've refreshed the page after I've pressed save on the form.
<?php
if(isset($_GET['vat_number'])) {
$vat_number = $_GET['vat_number'];
update_user_meta(get_current_user_id(), 'vat_number', $vat_number);
$message = 'VAT Number successfully updated';
$notice_type= success;
wc_add_notice( $message, $notice_type );
} ?>
<?php $vat_number = get_user_meta( get_current_user_id(), 'vat_number', true ); ?>
<form name="setprices" action="#" method="GET">
<label for="lowPrice">Vat Number: </label>
<input type="text" id="vat_number" name="vat_number" value="<?php echo $vat_number ?>"/>
<input type="submit" value="update"/>
</form>
The wc_add_notice()
function saves a notice for the next view. So that's normal behaviour. Your code should fire, save the notice and refresh or redirect the user.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With