首页 > 解决方案 > Woocommerec 使用查询字符串添加到购物车重定向

问题描述

我正在尝试执行以下操作;如果产品有查询字符串 ?redirect-cart

  1. 单击“添加到购物车”时重定向到结帐
  2. 添加一个新的查询字符串 ?hide-custom-fields
  3. 将 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;
}

不管用。

标签: phpwoocommerce

解决方案


推荐阅读