How can i Toogle between 2 icons without reloading page in wordpress

i’m working in wordpress website,and i want to toogle between 2 icons carts one whene the cart is empty and the seconde display whene add items to the cart, i add this code:

<span class="wd-tools-icon <?php echo esc_attr( $icon_classes ); ?>">
            
    <?php if ( ! WC()->cart->is_empty() ) { ?>
        <img id="https:/.../images/cart.svg" class="wd-custom-icon" alt="" height="20.738" width="17.626">      
                            
    <?php } else{ ?>        
        <img decoding="async" src="https:/.../images/empty-cart.svg.svg" class="wd-custom-icon" alt="" height="20.738" width="17.626">      

   <?php } ?>                   

   <?php if ( '2' == $params['style'] || '5' == $params['style'] ) : ?>
        <?php woodmart_cart_count(); ?>
   <?php endif; ?>
</span>

Expand snippet

but i need to refresh the page for displaying the cart; i’m looking for a way make me toogle between the 2 icons without reloading the page,a will be thankful for any suggestion

Leave a Comment