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() );
相关文章