如何仅在某些产品上跳过woocomerce上的购物车页面? [英] How to skip cart page on woocomerce for certain products only?

查看:107
本文介绍了如何仅在某些产品上跳过woocomerce上的购物车页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将此添加到我的functions.php文件中:

I added this to my functions.php file :

add_filter ('woocommerce_add_to_cart_redirect', 'woo_redirect_to_checkout');
function woo_redirect_to_checkout() {
$checkout_url = WC()->cart->get_checkout_url();
return $checkout_url;
}

但是现在,所有产品都将海峡重定向到结帐处。我只想在一种产品中使用此选项。是我可以在同一个文件管理器中添加产品ID的一种方式吗?

But now, all the products are re-directing strait to check-out. I would like to have this option only in one product. Is that a way I can add a product ID to that same filer?

谢谢!

推荐答案

您需要在刚将其添加到购物车时获取该产品,然后检查是否要将此商品页面重定向到结帐页面。您需要在下面的代码中更改 $ desire_product ='certain_product'; 行,它肯定会工作。

You need to get the product when It is just added to cart , then check if for this product you want to redirect the cart page to checkout page . You need to change $desire_product = 'certain_product'; line on below code and It will definitely work.

add_filter( 'woocommerce_add_to_cart_redirect', 'woo_redirect_checkout' );

function woo_redirect_checkout() {
    global $woocommerce;
    $desire_product = 'certain_product';
    //Get product ID
    $product_id = (int) apply_filters( 'woocommerce_add_to_cart_product_id', $_POST['add-to-cart'] );

    //Check if current product is subscription
    if ( $product_id == $desire_product ){
        $checkout_url = $woocommerce->cart->get_checkout_url();
        return $checkout_url;
        exit;
    } else {
        $cart_url = $woocommerce->cart->get_cart_url();
        return $cart_url;
        exit;
    }
}

这篇关于如何仅在某些产品上跳过woocomerce上的购物车页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆