Redirect to woocommerce checkout after adding to cart – item already in cart

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

A: Before adding a product to the cart, it is possible to empty the cart so that the add_to_cart_redirect hook will always be called. Use the woocommerce_add_to_cart_validation hook to alter the cart before adding a new item.

/**
 * First clear the cart of all products
 */
function clear_cart_before_adding( $cart_item_data ) {
  global $woocommerce;
  $woocommerce->cart->empty_cart();

  return true;
}
add_filter( 'woocommerce_add_to_cart_validation', 'clear_cart_before_adding' );

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

tech