simpleCart(js)

items
Items:
Total:

'afterAdd' Event

arguments:

  • item: simpleCart.Item that was just added to the cart
  • isNew: boolean of whether the item is a new item to the cart, or was already there and simply incremented the quantity

The ‘afterAdd’ event is triggered immediately after an item has been added to the cart.  You can modify the item using the reference.

// basic callback example
simpleCart.bind( "afterAdd" , function( item ){
  console.log( item.get("name") + " was added to the cart!" );
});

// see if a new item has been added
simpleCart.bind( "afterAdd" , function( item , isNew ){
  if( isNew ){
    console.log( "A brand new item called " + item.get( 'name' ) + " was added to the cart" );
  }
});

// modify the items price based on weight
simpleCart.bind( "afterAdd" , function( item , isNew ){
  if( item.get( 'weight' ) > 10 ){
    item.price( 20 );
  } else {
    item.price( 15 );
  }
});

Comments

  1. Oct 10, 2012

    yami  said:

    hello im having problems with the add to cart button it only appears on the main page but not on the post pages ,how can i fix it so that the add to cat buttons appear on the post pages??

    i think the version is 2.2

Commenting is not available in this channel entry.