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

查看:137
本文介绍了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.

推荐答案

您可以在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 the latest versions of WooCommerce (>= 2.1) the function can be simplified as:

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

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

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