I would like to bypass cart page and redirect user to checkout page for a few products.
I have created the add to cart link for the product
<a href="http://example.net/?add-to-cart=1461">Product Name</a>
And I have the code below
add_filter( 'woocommerce_add_to_cart_redirect', 'woo_redirect_checkout' );
function woo_redirect_checkout() {
global $woocommerce;
$desire_product = 1461;
//Get product ID
$product_id = (int) apply_filters( 'woocommerce_add_to_cart_product_id', $_POST['add-to-cart'] );
//Check if current product is subscription
if ( $product_id == $desire_product ){
$checkout_url = $woocommerce->cart->get_checkout_url();
return $checkout_url;
exit;
} else {
$cart_url = $woocommerce->cart->get_cart_url();
return $cart_url;
exit;
}
}
from How to skip cart page on woocomerce for certain products only?. But the url redirect me to homepage instead. Just wondering where is the issue,
I have unchecked the add to cart behaviour at woocommerce settings as well.
Thanks in advance.