WooCommerce - Skip cart page redirecting to checkout page(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 - 跳过购物车页面重定向到结帐页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:WooCommerce - 跳过购物车页面重定向到结帐页面
基础教程推荐
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 如何替换eregi() 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
