0
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 intend to redirect to the main page if the cart is empty!
Redirecting is only possible if you refresh the page ( F5 ).
Thanks in advance!
Following your line of reasoning the path I see there would be javascript friend, try to take advantage of the jquery library.
– Rafael Andrade