3

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

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?

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
user3354767
  • 203
  • 2
  • 4
  • 14

1 Answers1

3

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

This code goes in function.php file of your active child theme (or theme) or also in any plugin file.

The code is tested and fully functional.


Edit: Since WooCommerce 3 replace wp_redirect( WC()->cart->get_checkout_url() ); by:

 wp_redirect( wc_get_checkout_url() );
Community
  • 1
  • 1
LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • I now experience a problem with Paypal payments. Lets say I add a product to cart and I am forced to the checkout page, where I choose paypal as a payment method. I am then redirected to Paypal. When I decide to cancel the payment, there is a link to take me back to the website. That link is pointed at my cart, not the checkout. That means the visitor comes in an endless loop between cart and checkout. Is there something I can do about that? – user3354767 Sep 28 '16 at 04:27
  • @user3354767 You should not get back to cart… Normally you can specify the gateway return Url in paypal portal settings (not in wordpress/woocommerce)… – LoicTheAztec Jan 23 '18 at 09:47