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; }