I have this code

*   Redirect to checkout after adding to cart
function themeprefix_add_to_cart_redirect() {
  global $woocommerce;
  $checkout_url = $woocommerce->cart->get_checkout_url();
  return $checkout_url;
add_filter('add_to_cart_redirect', 'themeprefix_add_to_cart_redirect');

The problem is clicking on a link like www.example.com/?add-to-cart=1234 will not trigger the add_to_cart_redirect hook if there is something already in the cart. It thinks that there is something already in the cart and there is nothing else to add. Only one of my products can be purchased at a time.

Where can I hook in to redirect at an earlier stage in the cart validation process?


Is there a way to empty the cart before adding the product 1234?


Read more here: Redirect to woocommerce checkout after adding to cart – item already in cart


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: