add_action('wp_ajax_id_add', 'add_to_id');
add_action('wp_ajax_nopriv_id_add', 'add_to_id');
function add_to_id() {
$arr_id = [];
if ( !empty( $_POST['variation_id'] ) ) {
$id = absint( esc_attr( $_POST['variation_id'] ) );
} else {
$id = absint( esc_attr( $_POST['product_id'] ) );
}
if ( $arr_id == explode( ',', $_COOKIE["wp_id"] ) ) {
return;
}
array_push($arr_id, $id);
setcookie( "wp_id", implode( ",", $arr_id ), time()+86400 * 30, COOKIEPATH, COOKIE_DOMAIN );
wp_die();
}
add_action( 'init', 'my_setcookie_example' );
function my_setcookie_example() {
setcookie( "wp_id", "", time()+3600 );
}
$arr = [41, 90, 48];
$arr_string = implode(",", $arr);
$cipher = "aes-128-gcm";
$ivlen = openssl_cipher_iv_length($cipher);
$iv = openssl_random_pseudo_bytes($ivlen);
$arr_string_encrypted = openssl_encrypt($arr_string, $cipher, $key, $options=0, $iv, $tag)
setcookie("id", base64_encode($arr_string_encrypted), time()+3600);
$arr_string_encrypted = base64_decode($_COOKIE['id']);
$ivlen = openssl_cipher_iv_length($cipher="AES-128-CBC");
$iv = substr($arr_string_encrypted, 0, $ivlen);
$hmac = substr($arr_string_encrypted, $ivlen, $sha2len=32);
$ciphertext_raw = substr($arr_string_encrypted, $ivlen+$sha2len);
$arr_string = openssl_decrypt($ciphertext_raw, $cipher, $key, $options=OPENSSL_RAW_DATA, $iv);
$arr = explode(',', $arr_string);
Я так понял заработало ?