mardi 16 mars 2021

Hide element if cart is empty (WordPress + WooCommerce)

I have a menu cart icon in my header. Currently, the menu cart icon is always visible. I would like it to be visible only if there are items in the cart. So I'm trying to make it so the menu cart icon is hidden if the cart is empty.

I tried:

add_action( 'wp_footer', function() {
    
    if ( WC()->cart->is_empty() ) {
        
        echo '<style type="text/css">.elementor-widget-hfe-cart{ display: none; }</style>';
    
    }

});

But it doesn't work. Why?

Aucun commentaire:

Enregistrer un commentaire