Как рассчитать полученную цену продукта в качестве промежуточного итога?
Привет, я создал детальную страницу корзины и извлек данные выбранного пользователем продукта. Но я не знаю, как рассчитать цену продукта как промежуточный итог.
Что я уже пробовал:
<table class="shop_table shop_table_responsive cart"> <thead> <tr> <th class="product-thumbnail">Image</th> <th class="product-name">Product </th> <th class="product-price">Price</th> <th class="product-quantity">Quantity</th> <th class="product-subtotal">Total</th> <th class="product-remove"> </th> </tr> </thead> <tbody> <?php $total = 0; $pro_id = $_COOKIE['product_id']; $pro_id = explode(',', $pro_id); foreach ($pro_id as $val) { $ans = "SELECT * FROM wm_products WHERE pro_id='$val'"; $result = $conn->query($ans); while($row = $result->fetch_assoc()){ ?> <tr class="cart_item"> <td class="product-thumbnail"> <a href="single-product.html"><img src="<?php echo $row['pro_img_path']; ?>" alt="" width="180" height="180"></a> </td> <td data-title="Product" class="product-name"> <a href="single-product.html"><?php echo $row['pro_name']; ?></a> </td> <td data-title="Price" class="product-price"> <span class="amount">Rs. <?php echo $row['pro_price']; ?></span> </td> <td data-title="Quantity" class="product-quantity"> <div class="quantity buttons_added"> <input class="minus" value="-" type="button"> <label>Quantity:</label> <input size="4" class="input-text qty text" title="Qty" value="1" name="cart[92f54963fc39a9d87c2253186808ea61][qty]" max="29" min="0" step="1" type="number"> <input class="plus" value="+" type="button"> </div> </td> <td data-title="Total" class="product-subtotal" align="right"> <span class="amount">Rs. <?php echo $row['pro_price']; ?></span> </td> <td class="product-remove"> <a class="remove remove_cart" href="#" dataid="<?php echo $row['pro_id']; ?>">×</a> </td> </tr> <?php $subtotal = $total + ($row['pro_price']); } } ?> <tr> <td colspan="4" align="right">Subtotal :</td> <td align="right"> <span class="amount">Rs. <?php echo $subtotal; ?> </span> </td> </tr> <?php ?> <tr> <td class="actions" colspan="6"> <div class="coupon"> <label for="coupon_code">Coupon:</label> <input placeholder="Coupon code" value="" id="coupon_code" class="input-text" name="coupon_code" type="text"> <input value="Apply Coupon" name="apply_coupon" class="button" type="submit"> </div> <input value="Update Cart" name="update_cart" class="button" type="submit"> <div class="wc-proceed-to-checkout"> <a class="checkout-button button alt wc-forward" href="checkout.php">Proceed to Checkout</a> </div> <input value="1eafc42c5e" name="_wpnonce" id="_wpnonce" type="hidden"><input value="/electro/cart/" name="_wp_http_referer" type="hidden"> </td> </tr> </tbody> </table>