Home › Forums › Backend Issues (wp-admin) › Saving URL-Parameter (Cookie) to an WC-Order via ACF › Reply To: Saving URL-Parameter (Cookie) to an WC-Order via ACF
The first thing I would do is to not show the field on the front end. For this use an acf/prepare_field filter
your_filter_name($field) {
if (!is_admin()) {
return false;
}
return $field;
}
As far as saving the cookie value to the field, there are a couple of way you can do this. I would try using an acf/save_post action with a priority > 10
I do not have all the details for this function, just an outline.
function your_save_function_name($post_id) {
// I am not exactly sure what goes in post type check
// this should be the WC order post type I think
if (get_post_type($post_id) != 'the right post type') {
return;
}
// check the value of the cookie
if (!empty($_COOKIE['your-cookie-name')) {
$value = code_here_to_get_value_to_set(); // depends on how your cookie value is stored
// use the field key to update the field --- NOT the field name
update_field('field_XXXXXXXX', $value. $post_id);
}
}
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.