php - Woocommerec 使用查询字符串添加到购物车重定向
问题描述
我正在尝试执行以下操作;如果产品有查询字符串 ?redirect-cart
- 单击“添加到购物车”时重定向到结帐
- 添加一个新的查询字符串 ?hide-custom-fields
- 将 CSS 应用于包含“字符串”的页面 URL</a>
我的工作是: 使用查询字符串和重定向清除 WooCommerce 购物车,并为 WooCommerce 中定义的产品类别自定义添加到购物车重定向
这就是我所拥有的:[更新]
add_filter( 'woocommerce_add_to_cart_redirect', 'add_to_cart_checkout_redirection', 99, 1 );
function add_to_cart_checkout_redirection( $url ) {
// If the URL contains redirect_cart
$url = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if ( false !== strpos( $url, 'redirect-cart' ) ) {
// Clear add to cart notice (with the cart link).
wc_clear_notices();
$url = wc_get_checkout_url().'?hide-custom-fields';
}
return $url;
}
不管用。
解决方案
推荐阅读
- codeigniter - 使用 VUEJS 在 axios 上发布 Codeigniter3 403 错误
- google-cloud-platform - 有没有办法在 Google Cloud 笔记本实例中设置过度使用内存?
- javascript - 如何使用赛普拉斯存根模块功能?
- python-3.x - 如何通过服务器将文本生成的列表发送到客户端
- azure - 通过基于证书的服务主体凭据访问 Azure 存储;azure.identity 与 azure.common.credentials
- java - 在终端中运行 sbt 命令时出现错误“:”
- javascript - create-react-app 静态站点 - 读取 JSON 文件
- python - 使用python组合多个.csv文件的有效方法
- python-3.x - 尽管符合 for 循环,为什么字符串没有从列表中删除?
- dataframe - 计算第一次出现并在列中分配一个值