Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manuelhudec/b1a9971d545e021539ad43628d750099 to your computer and use it in GitHub Desktop.
Save manuelhudec/b1a9971d545e021539ad43628d750099 to your computer and use it in GitHub Desktop.
WooCommerce - Shopping cart redirect to checkout
add_action( 'template_redirect', function() {
// Replace "cart" and "checkout" with cart and checkout page slug if needed
if ( is_page( 'cart' ) ) {
wp_redirect( '/checkout/' );
die();
}
} );
add_action( 'template_redirect', 'redirect_empty_checkout' );
function redirect_empty_checkout() {
if ( is_checkout() && 0 == WC()->cart->get_cart_contents_count() && ! is_wc_endpoint_url( 'order-pay' ) && ! is_wc_endpoint_url( 'order-received' ) ) {
// Replace "shop" with your Shop page slug if needed
wp_safe_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) );
exit;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment