問題描述
我們的網站是 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模板網!