Redirect to checkout page after adding to WooCommerce cart

Sometimes it is required to add a redirect to the cart or to the checkout page after adding the product to the cart.

Snippet for redirect to cart:

function add_to_cart_redirect_to_cart() {
    wp_safe_redirect( get_permalink( get_option( 'woocommerce_cart_page_id') ) );
add_action('woocommerce_add_to_cart','add_to_cart_redirect_to_cart', 100 );

Snippet for redirect to checkout page:

function add_to_cart_redirect_to_checkout() {
    wp_safe_redirect( get_permalink( get_option( 'woocommerce_checkout_page_id') ) );
add_action('woocommerce_add_to_cart','add_to_cart_redirect_to_checkout', 100 );

Updated: 10.11.2018

Did this article help you? Rate it!
(No Ratings Yet)

Leave a Reply

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


Send message