简体   繁体   中英

shopp plugin add existing cart item with custom price

I have normal product with price 29$, what I want is by charging extra 10$ on this and give another item (same product) , means buy one in 29$ and buy two in 39$.

For this I have using this code to add product to cart

<?php
if($_POST['duplica_las_flores'] != '' && isset($_POST['duplica_las_flores']))
{

    $customProdcutId = $_POST['productID'];
    if(is_numeric($customProdcutId))
    {
        global $Shopp; //load up our $Shopp variable

        $Product = new Product(absint($customProdcutId)); //We have to create a Product object to use in our add to cart function.
        if(!empty($Product->id)){
            $pricing = 10.00;
            $result = $Shopp->Order->Cart->add(1, $Product, $pricing, false, array(), array()); //This is where "the magic happens"
        }
}
?>

In this if checkbox is checked in single product page then this will add another product with my custom price (10$) but this is adding new product with same price (29$).

How can I change price here for second product or is there any other way to do this ?

Thanks

Easier than modifying the cart code, would to be to use the built in Add-ons system, and create an add on for adding an additional item.

Pros: Save yourself some time messing around in the plugin code

Cons: No inventory updating if you're dealing with a physical product

I couldn't find the documentation for it, but 'Add-ons' are mentioned here: https://shopplugin.net/docs/the-catalog/product-settings/

如果您没有太多不同的产品采用这种定价方式,则可以查看折扣

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM