• Resolved jonasojczyk

    (@jonasojczyk)


    Hello,

    Please help me with this. https://lndecals.dk/norsk-luftambulanse-norwegian-air-ambulanse-ec145/https://lndecals.dk/cart/

    Help me make the cart page automatically refresh when removing all products from the cart.

    I found code to redirect from cart to shop, once cart is empty. But issue is persistent since cart page isn’t refreshed upon emptying the cart.

    add_action( ‘template_redirect’, ’empty_cart_redirection’ );
    function empty_cart_redirection(){
    if( is_cart() ) :

    // Here set the url redirection
    $url_redirection = get_permalink( wc_get_page_id( ‘shop’ ) );

    // When trying to access cart page
    if( WC()->cart->is_empty() ){
    wp_safe_redirect( $url_redirection );
    exit();
    }
    // When emptying on cart page
    wc_enqueue_js( “jQuery(function($){
    $(document.body).on( ‘wc_cart_emptied’, function(){
    if ( $( ‘.woocommerce-cart-form’ ).length === 0 ) {
    $(window.location).attr(‘href’, ‘” . $url_redirection . “‘);
    return;
    }
    });
    });” );
    endif;
    }`

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Reload/refresh empty cart page’ is closed to new replies.