WooCommerce-跳过购物车页面重定向到结帐页面 [英] WooCommerce - Skip cart page redirecting to checkout page

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

问题描述

我们的网站是 kohsamuitour.net .我添加了自定义代码,以在结帐时跳过购物车页面,该页面适用于所有销售.这段代码:

Our website is kohsamuitour.net. I have added custom code to skip the cart page on checkout, which works for all sales. This code:

function wc_empty_cart_redirect_url() {
return 'https://www.kohsamuitour.net/all-tours/';
}
add_filter( 'woocommerce_return_to_shop_redirect',     'wc_empty_cart_redirect_url' );

现在可以完成工作,但我们也可以检查预订的可用性.可以在私人章程的页面上找到,即: https://www .kohsamuitour.net/tours/kia-ora-catamaran/.

Now that does the job, but we also have a possibility to check booking availability. That can be found on the pages of private charters, i.e. this one: https://www.kohsamuitour.net/tours/kia-ora-catamaran/ .

在这里,客户被重定向到购物车,我不希望发生这种情况,因为这不是销售.

Here the customer is being redirected to the cart, where I don't want that to happen as this is not a sale.

如何确保检查预订可用性"也立即重定向到结帐处?

How can I make sure the 'Check booking availability' is also redirected to the checkout straight away?

推荐答案

您可以确定地跳过购物车,在调用购物车URL时将客户重定向到结帐页面.

You can skip cart definitively, redirecting customers to checkout page when cart url is called.

要使用此代码段来实现此目的,应该做到这一点:

To achieve this use this code snippet, that should do the trick:

// Function that skip cart redirecting to checkout
function skip_cart_page_redirection_to_checkout() {

    // If is cart page, redirect checkout.
    if( is_cart() )
        wp_redirect( WC()->cart->get_checkout_url() );
}
add_action('template_redirect', 'skip_cart_page_redirection_to_checkout');

此代码会出现在您活动的子主题(或主题)的function.php文件中,也可能会出现在任何插件文件中.

该代码已经过测试并且功能齐全.

The code is tested and fully functional.

由于WooCommerce 3将wp_redirect( WC()->cart->get_checkout_url() );替换为:

Since WooCommerce 3 replace wp_redirect( WC()->cart->get_checkout_url() ); by:

 wp_redirect( wc_get_checkout_url() );

这篇关于WooCommerce-跳过购物车页面重定向到结帐页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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