cart page redirect

PHOTO EMBED

Mon May 06 2024 08:24:47 GMT+0000 (Coordinated Universal Time)

Saved by @mastaklance

/**
 *  Custom cart redirection: / home page when cart is empty and checkout page if cart is not empty
 */

add_action('template_redirect', 'custom_cart_redirections');
function custom_cart_redirections() {
    if ( is_cart() ) {
        if ( WC()->cart->is_empty() ) {
            wp_redirect( home_url('catalog') );
            exit();
        } else {
            wp_redirect( wc_get_checkout_url() );
            exit();
        }
    }
}
content_copyCOPY