Solution:
I chose another approach and a WordPress hook instead of woocommerce. This is based on this answer: WooCommerce – Skip cart page redirecting to checkout page
This is that code:
function skip_cart_page_redirection_to_checkout() {
// desired product id redirection
$product_id = 1461;
$items_ids = array();
// Get all items IDs that are in cart
foreach( WC()->cart->get_cart() as $item ) {
$items_ids[] = $item['product_id'];
}
// If is cart page and the desired peoduct is in cart => redirect to checkout.
if( is_cart() && in_array($product_id, $items_ids) )
// WooCommerce 3.0 compatibility added
if ( version_compare( WC_VERSION, '2.7', '<' ) ) {
wp_redirect( WC()->cart->get_checkout_url() ); // Older than 3.0
} else {
wp_redirect( wc_get_checkout_url() ); // 3.0+ (Thanks to helgatheviking)
}
}
add_action('template_redirect', 'skip_cart_page_redirection_to_checkout');
This code goes in function.php file of your active child theme (or theme) or also in any plugin file.
The code is tested and fully functional.