[英]Set cookie and redirect if cookie set based on url
我正在运行 woocommerce/wordpress 并注意到客户刷新感谢页面会导致谷歌分析记录多笔交易。
他们访问的url是:/checkout/order-received/24420/?key=wc_order_a5m1jzQDJLjjr
我想我需要使用该订单号设置一个 cookie。 如果 cookie 存在,则在分析代码运行之前重定向。 从而防止重新加载感谢页面..(我希望)
我不知道是谁从 url 中提取数字 24420 并设置 cookie。 在 Cookie 上重定向我可以弄清楚。
谢谢
/J
检索订单 ID
$order_id = wc_get_order_id_by_order_key( $_GET['key'] );
我建议使用 session 而不是 cookie,这样您就可以执行类似的操作
if(isset($_SESSION['order_'.$order_id])) {
header("Location: /where-you-want");
die;
} else {
$_SESSION['order_'.$order_id] = 1;
}
Please note that both Session and Cookies need to be set before any other output on the page , so be sure that the code you're running is executed before any HTML is printed.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.