Custom Button that add to cart and automatically redirect to checkout

I’d like to create a custom button on a product page that needs to add automatically the product i’m on into the cart and send you with that product details to the checkout page.

What i’ve tried so far :

<?php do_action( 'woocommerce_proceed_to_checkout' ); ?>

That doesnt send you on the checkout if you dont have at least 1 product in cart.

function add_to_cart_checkout_redirect() {
    wp_safe_redirect( get_permalink( get_option( 'woocommerce_checkout_page_id' ) ) );
    die();
}
add_action( 'woocommerce_add_to_cart',  'add_to_cart_checkout_redirect', 11 );

Also doesnt work.

Question:

Can be done?
Am i wrong somewhere?

Thanks in advance.

Read more here: Custom Button that add to cart and automatically redirect to checkout

Leave a Reply

Your email address will not be published. Required fields are marked *