add_action( 'wp_footer', 'redirecionar' );
function redirecionar(){
global $woocommerce;
if ( is_page('carrinho-de-compras') and !sizeof($woocommerce->cart->cart_contents) ) {
wp_redirect( get_home_url() );
exit();
}
}
OR
add_action( 'template_redirect', 'redirecionar' );
function redirecionar(){
global $woocommerce;
if( is_cart() && WC()->cart->cart_contents_count < 1 ){
wp_safe_redirect( get_permalink( woocommerce_get_page_id( 'shop' ) ) );
}
}
I want to redirect to the homepage if the cart is empty! Redirection is only possible if you refresh the page (F5).
Thanks in advance!