I added this to my functions.php file :
add_filter ('woocommerce_add_to_cart_redirect', 'woo_redirect_to_checkout');
function woo_redirect_to_checkout() {
$checkout_url = WC()->cart->get_checkout_url();
return $checkout_url;
}
But now, all the products are re-directing strait to check-out. I would like to have this option only in one product. Is that a way I can add a product ID to that same filer?
Thank you!
There are a few action hooks as well that you can use, for eg:
woocommerce_add_to_cart
which passes the product id to the callback function:You need to get the product when It is just added to cart , then check if for this product you want to redirect the cart page to checkout page . You need to change
$desire_product = 'certain_product';
line on below code and It will definitely work.I wrote a little plugin for this, sharing it here. The plugin adds a small checkbox to the product metabox, so you can specify which products should trigger the automatic skip to checkout. Basically using the same
woocommerce_add_to_cart_redirect
filter as in the other answers, but providing the admin backend option to determine which products trigger the redirection.