Woocommerce 添加到购物车按钮重定向到结帐 [英] Woocommerce add to cart button redirect to checkout

查看:37
本文介绍了Woocommerce 添加到购物车按钮重定向到结帐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用插件 woocommerce 创建了一个电子商务.我只出售订阅,所以/cart/"页面没用.我试图摆脱它,以便当我的客户点击添加到购物车"按钮时,他最终会出现在结帐页面上.

I created an ecommerce using the plugin woocommerce. I am selling only a subscription so the "/cart/" page is useless. I'm trying to get rid of it so that when my customer click on "Add to cart" button, he ends up on the checkout page.

推荐答案

在 WooCommerce 3.6 或更高版本中,您可以使用 woocommerce_add_to_cart_redirect (props @roman)

In WooCommerce 3.6 or later you can use woocommerce_add_to_cart_redirect (props @roman)

add_filter ('woocommerce_add_to_cart_redirect', function( $url, $adding_to_cart ) {
    return wc_get_checkout_url();
}, 10, 2 ); 


原答案:


Original answer:

你可以在functions.php中使用过滤器:

you can use a filter in functions.php:

add_filter ('add_to_cart_redirect', 'redirect_to_checkout');

function redirect_to_checkout() {
    global $woocommerce;
    $checkout_url = $woocommerce->cart->get_checkout_url();
    return $checkout_url;
}

它似乎不适用于 ajax,但它适用于单个产品页面,我认为这是您使用的

it doesn't seem to work with ajax, but it works from the single product pages, which I think is what you use

在 WooCommerce (>= 2.1) 上,该函数可以简化为:

On WooCommerce (>= 2.1) the function can be simplified as:

function redirect_to_checkout() {
    return WC()->cart->get_checkout_url();
}

这篇关于Woocommerce 添加到购物车按钮重定向到结帐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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