called when an item is added to the cart.

add_action('shopp_cart_add_item', [callback] );

@param Item $Item the Cart Item object.


This action is called when a new item is successfully added to the cart. See Parameters passed to the [callback].


add_action('shopp_cart_add_item', 'my_function');
function my_function ( $Item ) {
// do stuff

See Also

  1. I’m using this hook to add +£1 for each meter of wire ordered. The customer enters a number into a custom product field and a new price is calculated using the shopp_cart_add_item hook.

    This function will recalculate the unit price of the product and the taxable amount.

    Take a look at the code below from my themes functions.php to see how it’s done:

    function calculate_new_price(&$NewItem)
        global $Shopp;</p>
    $Order  =& ShoppOrder();
    $Cart   =& $Order->Cart;
    if (!$Cart) return;
    shopp('catalog','product','id='.$NewItem->product); // load the product to get access to the product specs
        $key = array_search($NewItem, $Cart->contents);
        if ( isset($key) )
            //Calculate the new price of the item
            $inputvalue = $NewItem->data['customLength']; //get the value inputed by the user (length)
            $roundedvalue = ceil($inputvalue); //round up the input value
            $newprice = $Cart->contents[$key]->unitprice + $roundedvalue; //add the rounded input value to the price
            $Cart->contents[$key]->unitprice = $newprice; // set the unitprice to be the newly calculated price
            //Change the taxable amount so that tax is recalculated
            $Cart->contents[$key]->taxable = array($Cart->contents[$key]->unitprice);
    March 6th   #

  2. I used this action hook in the form of a custom product calculator. Using Ralphs code I was able to achieve this

    // Custom Products Banner
        function before_cart($Item){
            global $Shopp;
                $Order =& ShoppOrder();
                $Cart =& $Order->Cart;
                if(!$Cart) return;
                if($Item->product == 360): // Filter Custom banner product
                        shopp('catalogue','product','id='.$Item->product.''); // Load product information
                        $key = array_search($Item, $Cart->contents); 
                            $width  = $Item->data['width']; // Get Width of product
                            $height = $Item->data['height'];// Get Height of product
                            $price = $Cart->contents[$key]->unitprice; // Get current Unit Price of product (£1.50)
                            $quantity = $Item->quantity; // Get Quantity of product
                            $area  = $height * $width; // Calculate area
                            $total = $area * $price; // Get New Total
                            $total = $total * $quantity; // Final Total after Quantity selection
                            $Cart->contents[$key]->unitprice = $total; // Assign total to product unit cost
                            $Cart->contents[$key]->taxable = array($Cart->contents[$key]->unitprice); // Calculatre tax based on that unit cost
        return $Item;
        add_action('shopp_cart_add_item', 'before_cart');
    January 28th   #

You must be logged in to post a comment.

© Ingenesis Limited. Shopp™ is a registered trademark of Ingenesis Limited.