I have implemented minicart js into my website, and I can add items to the cart and it works properly. What I would like to do, is say when a user adds 2 items at a particular price (say 11.99) it will discount it down to 20.
I know there is a discount function for minicart js but the documentation isn't too clear. I would just like to know the best way to achieve this?
here is the code I'm working with:
<?php
// Connect to the MySQL database
include "store_scripts/connect_to_mysql.php";
$dynamicList = '';
$sql = mysqli_query($dbc, "SELECT * FROM products where category = 'Rings'");
$productCount = mysqli_num_rows($sql);
if($productCount > 0)
{
while($row = mysqli_fetch_array($sql))
{
$id = $row['id'];
$product_name = $row['product_name'];
$price = $row['price'];
$date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
$dynamicList .= '
<div id="floatedImage">
<a href="product.php?id=' . $id . '"><img src="images/' . $product_name . '.jpg" alt="' . $product_name . '" /></a>
<p>' . $product_name . '</p>
<p>€' . $price . '</p>
<p><a href="product.php?id=' . $id . '">View Product Details</a><p>
<form target="paypal" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart"/>
<input type="hidden" name="business" value="[email protected]"/>
<input type="hidden" name="item_name" value="' . $product_name . '"/>
<input type="hidden" name="amount" value="' . $price . '"/>
<input type="hidden" name="currency_code" value="EUR"/>
<input type="hidden" name="add" value="1"/>
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_cart_LG.gif" name="submit" alt="PayPal - The safer, easier way to pay online!"/>
<img alt="" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1"/>
</form>
</div>';
}
}
else
{
$dynamicList = "We have no products listed in our store yet";
}
mysqli_close($dbc);
?>
<!DOCTYPE html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link href="css/styles.css" rel="stylesheet" type="text/css" media="screen"/>
<title>Rings</title>
</head>
<body>
<div id="wrapper">
<div id="top">
<?php include('templates/top_template.php'); ?>
</div>
<div id="topnav">
<?php include('templates/topnav_template.php'); ?>
</div>
<div id="banner">
</div>
<div id="content">
<p><?php echo $dynamicList ?></p>
</div>
<div id="rightSide">
<?php include('templates/rightSide_template.php'); ?>
</div>
<div id="footer">
<?php include('templates/footer_template.php'); ?>
</div>
<div id="copyrightFooter">
<?php include('templates/copyrightFooter_template.php'); ?>
</div>
<script src="minicart.js"></script>
<script>
paypal.minicart.render();
</script>
</div>
</body>
</html>