Woocommerec使用查询字符串添加到购物车重定向

时间:2020-07-23 14:58:58

标签: php woocommerce

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

  1. 点击“添加到购物车”时重定向至结帐
  2. 添加新的查询字符串?hide-custom-fields
  3. Apply CSS to a Page URL That Contains “string”

我的工作地点是: Clear WooCommerce Cart with a Query String and Redirectcustom add to cart redirection for a defined product category in 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;
}

不起作用。

0 个答案:

没有答案