如何计算取得的产品价格作为小计? [英] How to calcute fetched product price as subtotal?

查看:113
本文介绍了如何计算取得的产品价格作为小计?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了购物车详细信息页面并获取了用户所选产品的数据。但是,我不知道如何将产品价格计算为小计。



我尝试了什么:



Hi, i created cart detail page and fetched data of user selected product. But, i don't know how to calcute product price as subtotal.

What I have tried:

<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>

推荐答案

总计 = 0 ;
total = 0;


pro_id =
pro_id =


_COOKIE [' product_id'];
_COOKIE['product_id'];


这篇关于如何计算取得的产品价格作为小计?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆