Tuesday, March 12, 2013

How to Show/Hide Wpcommerce Shopping Cart Widget

Using jQuery you can very quickly setup functionality to show & hide the cart widget in wpcommerce. Just add the below snippet to the wpsc-cart_widget.php in your template override file at the top. Blam, done.

 When the customer clicks on add to cart button, the widget will show and be updated with the new price. When the user clicks clear cart, it hides.

Simple. The second part automatically hides the cart when its empty. This could also be done with CSS.

<script type="text/javascript">
jQuery(function(){
    
            
        jQuery('.wpsc_buy_button').click(function(){
            jQuery('.widget_wpsc_shopping_cart').show();
        });
        jQuery('.emptycart').click(function(){
            jQuery('.widget_wpsc_shopping_cart').hide();
        });
        
})
</script>


<?php if(wpsc_cart_item_count() <= 0)
{ ?>
<script type="text/javascript">
jQuery(function(){
    
    jQuery('.widget_wpsc_shopping_cart').hide();
  
})
</script>
<?php } ?>


Stumble Upon CodePyro

No comments:

Post a Comment