Woo Commerce One Product only, Skip the cart page

Sometime there is situation where custom sells only One product. At that time they do not require cart page before checkout. So taking them to checkout page is the right thing this will make purchase process shorter.

below code snippet clears the cart, adds the product to it and then redirects to the checkout page.

What this script does is:
1. Check that it’s a click on one of the ‘buy’ links.
2. Get the ID of the product we’re adding to the cart. This ID comes from the ‘buy’ link.
3. Empty the cart, in case a different product was selected before.
4. Add the new product to the cart.
5. Redirect to the checkout page (skipping the cart page).

Allow to add link in WordPress Widget Title

Code used in this video