WooCommerce - 跳过购物车页面重定向到结帐页面

时间:2023-03-19
本文介绍了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 - 跳过购物车页面重定向到结帐页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

上一篇:在 WooCommerce 格式的产品尺寸输出中将长度重命名 下一篇:在 Woocommerce 中仅显示特定客户所在国家/地区的价

相关文章

最新文章