68
Here’s how you force redirection to the checkout page every time a product is added to cart, no matter if you do so from the loop/shop pages or the single product page.
On top of adding the code to your functions.php you also need to double check your WooCommerce settings, see screenshot below. Enjoy!
1. WooCommerce Settings
Go to WooCommerce > Settings > Products > General and disable both options: “Redirect to the cart page after successful addition” & “Enable AJAX add to cart buttons on archives“:
2. PHP Snippet: Redirect to Checkout on Add to Cart – WooCommerce
/**
* @snippet Redirect to Checkout Upon Add to Cart - WooCommerce
* @how-to Get tutoraspire.com FREE
* @author Tutor Aspire
* @compatible Woo 3.8
* @donate $9 https://tutoraspire.com
*/
add_filter( 'woocommerce_add_to_cart_redirect', 'tutoraspire_redirect_checkout_add_cart' );
function tutoraspire_redirect_checkout_add_cart() {
return wc_get_checkout_url();
}