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!
ACF wouldn’t be so widely used in WordPress if it didn’t have some pretty amazing capabilities. In this article, we look at a few of the features we’ll discuss during “7 things you didn’t know you could do with ACF” at #WPEDecode later this month. https://t.co/5lnsTxp81j pic.twitter.com/Yf0ThPG1QG
— Advanced Custom Fields (@wp_acf) March 16, 2023
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.