I wish to make multiple specific subscription products skip the cart and go straight to checkout. I found the following code here (only for one product), which skips it for one product using the product ID, but unable to adapt it for multiple products. Tried also various other methods, but none seem to work for Woocommerce 4.51
How to skip cart page on woocomerce for certain products only?
add_filter( 'woocommerce_add_to_cart_redirect', 'woo_redirect_checkout' );
function woo_redirect_checkout() {
global $woocommerce;
$desire_product = '73458';
//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;
}
}