I have a product in woocommerce which has a custom field created using ACF.
I need to update the product custom field from a form before the customer checks out, the value submitted will be different every time.
The default value for the custom field goes through to checkout ok, but im struggling to update this field from the form being submitted, the new variables submitted do show up on the page when testing, but does update the ACF field for the produce on checkout.
Ive tried with this code (im not a coder) and help would be appreciated
<?php
acf_form_head();
$ex_ACF_dom = (string) get_field('field_6112e97117f8');
echo "Pulled from ACF: $ex_ACF_dom";
echo "</br>";
$variable = $_POST['ald'];
echo "</br>";
echo "Data from form submitted: $variable";
echo "</br>";
if(isset($_POST['ald'])){
update_field('field_6112e97117f8', $variable);
echo "</br>";
echo "New field in ACF: $variable";
echo "</br>";
$exchange_ACF_domain = (string) get_field('field_6112e97117f8');
echo "</br>";
echo "Name has changed: $ex_ACF_dom";
echo "</br>";
}?>
<form action="" method="post">
<p style="text-align:center;">
Value to use:<br>
<p>Dom: <input type="text" id="ald" name="ald" /></p>
<input type="submit" name="submit" value="add to order">
</p>
</form>
2
Answers
simple solution to fix, I didn't define the post_id
Is ‘field_6112e97117f8’ the actual slug of your field, that you’ve added in ACF section in backend? If not, you should change it for actual one.