wojodesign / simplecart-js

A simple javascript shopping cart that easily integrates with your current website.
simplecartjs.org
1.79k stars 490 forks source link

Show Checkout Link Only products Added #485

Open bonucci opened 10 years ago

bonucci commented 10 years ago

Hello there, can anybody tell me How can i make the Checkout Link appear/show only when there is procuts added to the cart?

irsah commented 9 years ago

Hope this will help somebody...

Use "afterAdd" or "beforeSave" functions built with simpleCart. In this case checkout button to appear/show when product is added (or maybe if user empties the cart) then use both of the functions:-

<script>
simpleCart.ready(function(){
    // get the checkout button into var
    var button = $('.simpleCart_checkout');
    // hide the checkout button
    button.hide();
    // get the cart quantity
    var quantity = simpleCart.quantity();

    // do something if item added to cart
    simpleCart.bind('afterAdd',function(){
        if(quantity > 0){
             button.show(); // shows the button
        } 
    });

    // this handles/checks if the cart is emptied by user
    // and hides back the checkout button if empty cart
    simpleCart.bind('beforeSave',function(){
        // do something when quantity is 0 (empty)
        if(quantity == 0){
             button.hide(); // hides the button if cart is emptied
        } 
    });
});
</script>

Method is used at our blogrcart e-commerce inspired themes for blogger using simpleCartjs http://blogrcart-closet.blogspot.com. Adding/removing product utilizes these functions..

Edit

You can also add a style="display:none" to the button and remove the css property when item added using jquery at above. This helps if the checkout button can be easily seen/accessed during page rendering (especially slow internet lines) before the scripts initialize. So users do not have a chance to click it if the script is not fully initiated.

alejarg commented 8 years ago

Hola.........en mi caso la solución que implemente fue modificar en archivo simplecart.js en " CHECKOUT MANAGEMENT"...... agregue estas lineas

var quantity = simpleCart.quantity(); if ( quantity<= 0) {return simpleCart.error('No hay artículos en el carro');}

Dejo el comentario esperando ayudar a alguien

arraymultimedia commented 7 years ago

Try something like this:

var mintotal = 100; simpleCart.bind( 'ready' , function(){ var total = simpleCart.total(); if(total > mintotal){ button.hide(); } else { button.show(); } });

simpleCart.bind( 'update' , function(){ var total = simpleCart.total(); if(total > mintotal){ button.hide(); } else { button.show(); } });