Increase cart cost if X is met
So we have an issue with using a silly item/product based shipping, aka the user adds a product to the cart (FedEx/USPS) and the cost is added to shipping. If X amount of items are in teh cart, the rate increases due to products being shipped via envelope to being shipped via box. This incurs an additional 20$ service charge. I would like to append an additional 20$ to cart costs if X items are met, but am having an issue with adding this to the session information (and having it stick). Using this code, I can add an additional cost to shipping:
# %install_dir%/cata开发者_运维百科log/checkout_shipping.php
$_SESSION['cart']->total = $_SESSION['cart']->total + 20;
var_export($cart);
This does not reflect in my shopping cart module/sidebar with he current price though. Help would be appreciated!
Is there a "session_start()" somewhere in this script prior to these lines?
session_start();
$_SESSION['cart']->total += 20;
Also, you might not want to put it right in the total. I'd put it in a shipping related variable, as well as add it to the running total. That way you can make sure you don't add it again if you've already done it once! Like:
session_start();
if (!$_SESSION['cart']->shipping_extra) {
$_SESSION['cart']->shipping_extra = true;
$_SESSION['cart']->total += 20;
}
Also... # is deprecated, use // or /* !
精彩评论