/** * 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(); } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter