When adding a product to my cart, I’m recording a cookie with the id of the post from which the product was added.

A cookie is written with the name 'idp' and in the value, respectively, id. Cook spelled properly and at the time of payment confirmation it is already in place. verified.

But then at the moment when the payment is made and the order goes to the "completed" stage, I try to take the necessary information from the cookie and nothing comes out.

add_action('woocommerce_order_status_completed', 'ustanovka_oplaty'); function ustanovka_oplaty( $post_id ) { $idp = $_COOKIE['idp']; } 

what could be the problem?

Can there be an alternative simple way to transfer to the order the id of the post on which the product was added?

Cookies are set as follows:

 add_action( 'init', 'wpcd_set_cookie', 1 ); function wpcd_set_cookie() { if(isset( $_POST[ 'idp' ] ) ) : $cookie_value = sanitize_text_field( $_POST[ 'idp' ] ); setcookie( 'idp', $cookie_value, time() + (86400 * 999), "/" ); // 86400 = 1 day header("Refresh:0"); endif; } 
  • perhaps you incorrectly set cookies. Show the full code where the cooks are recorded. - And
  • Cookies are installed, checked many times. add_action ('init', 'wpcd_set_cookie', 1); function wpcd_set_cookie () {if (isset ($ _POST ['idp'])): $ cookie_value = sanitize_text_field ($ _POST ['idp']); setcookie ('idp', $ cookie_value, time () + (86400 * 999), "/"); // 86400 = 1 day // Now you can get a captured header ("Refresh: 0"); // exit; endif; - pan1ka
  • And how did you check that the cookies are set? The code says nothing. In the browser, do you see these cookies? - KAGG Design
  • yes, of course, they appear in the browser - pan1ka

0