简体   繁体   English

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

[英]WooCommerce - Skip cart page redirecting to checkout page

Our website is kohsamuitour.net .我们的网站是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' );

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, ie this one: https://www.kohsamuitour.net/tours/kia-ora-catamaran/ .这可以在私人包机的页面上找到,即这个: 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?我如何确保“检查预订可用性”也被直接重定向到结账页面?

You can skip cart definitively, redirecting customers to checkout page when cart url is called.您可以明确地跳过购物车,在调用购物车 url 时将客户重定向到结帐页面。

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');

This code goes in function.php file of your active child theme (or theme) or also in any plugin file.此代码位于活动子主题(或主题)的 function.php 文件或任何插件文件中。

The code is tested and fully functional.代码已经过测试并且功能齐全。


Edit: Since WooCommerce 3 replace wp_redirect( WC()->cart->get_checkout_url() );编辑:由于 WooCommerce 3 替换wp_redirect( WC()->cart->get_checkout_url() ); by:经过:

 wp_redirect( wc_get_checkout_url() );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM