• Resolved Ivan Shatsky

    (@ivan-shatsky)


    Hello,
    This question already asked by several users, but I want to suggest a workaround for this problem. Since the message returned by get_refreshed_fragments AJAX request when default mini-cart template is used did not changed since WooCommerce 3.1.0, the following code can be used to solve the problem:

    
    if( optimocha_getCookie("woocommerce_cart_hash") ) {
        ...
    } else {
        addEventListener("DOMContentLoaded", function() {
            if (shopping_carts = document.querySelectorAll("div.widget_shopping_cart_content")) {
                shopping_carts.forEach(function(cart_content) {
                    cart_content.innerHTML = "<p class=\\"woocommerce-mini-cart__empty-message\\">' . esc_html__( 'No products in the cart.', 'woocommerce' ) . '</p>";
                });
            }
        });
    }
    

    An option to use or do not use this code can be added to the WP admin interface.

Viewing 1 replies (of 1 total)
  • Plugin Author Optimocha

    (@optimocha)

    Thanks @ivan-shatsky! Definitely not an invalid solution, but it can only be applied to the theme you’re using. The cart fragments script generates different cart fragments for different themes, thus there’s no universal cart fragment that applies to all websites (or themes).

    However, I really like your method of replacing cart contents. We’re working on a “default cart fragment” solution and we will definitely use a similar method to inject the default fragment. We’ll probably release the new version this month, so stay tuned! ??

    • This reply was modified 4 years, 5 months ago by Optimocha.
    • This reply was modified 4 years, 5 months ago by Optimocha.
Viewing 1 replies (of 1 total)
  • The topic ‘Empty cart HTML contents’ is closed to new replies.