• 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)
  • Thread Starter jonasojczyk

    (@jonasojczyk)

    Mirko P.

    (@rainfallnixfig)

    Hi @jonasojczyk,

    Thanks for reaching out!

    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.

    Could you elaborate a bit on the above statement? Do you want to redirect the cart page to the shop page once all items in the cart are removed?

    Please consider that this is out of our scope of support but I’m going to leave the thread open for a bit to see if anyone is able to chime in to help you out.

    You can also visit the WooCommerce Facebook Community group or the #developers channel of the WooCommerce Community Slack. We’re lucky to have a great community of open-source developers for WooCommerce, and many of our developers hang out there, as well.

    Cheers.

    Thread Starter jonasojczyk

    (@jonasojczyk)

    @rainfallnixfig Hello,

    Thanks for the clarification. I’m going to find help somewhere else.

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

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