Home Forums Backend Issues (wp-admin) Saving URL-Parameter (Cookie) to an WC-Order via ACF


Saving URL-Parameter (Cookie) to an WC-Order via ACF

  • Hey everybody,

    i want to save an URL-Parameter that we also store in a Browser-Cookie to an Order. This way i want to check if Cooperations, Google Ads etc. work and add something to the order if e.g.someone came from a Blog-Post-Cooperation. I dont want to use Coupons for that.

    Any idea?

    I already created ACF Text-Fields for the Orders but i dont know how to save the cookie-value in it.

    All the best

  • Will this field be something that the person submitting the order should be able to see?

  • No – only for the backend / me, packing packages etc.

  • 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') {
      // 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);
Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

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.