Redirect to checkout woocommerce failed

Well, what it works for me in this case was this code

add_filter( 'woocommerce_add_to_cart_redirect', 'redirect_add_to_cart' );

function redirect_add_to_cart() {       
    if ( isset( $_POST['add-to-cart'] ) ) {
        $url = wc_get_checkout_url();
        return $url;
    }       
}

It redirects if it is a product but if you are in the shop page it wont redirect, of course if you want to redirect in another page but in single product page the code should be if ( !isset( $_POST['add-to-cart'] ) ) {

I hope my question and answer helps somebody who visits this post