我想在我的wordpress网站中集成自定义价格功能。我正在使用woocommerce插件。
目标是计算产品的实际价格并将其发送到购物车页面,例如:80 *上限值为 2.5 ,即3 * 80 = 3 = 240 $ 240 $ 应该传递到产品的购物车页面
我创建了4个不同选项的下拉菜单,这些下拉菜单会更改前,副和后仪表的值。我还通过将价格除以米值来计算单米胶带的价值。Eg: 200/2.5 = 80$/meter
这是正常价格200。
代码:
// UI
<div class="col-sm-6 col-sm-offset-3">
<button class="btn btn-success buttonvc" type="submit" name="calculate">Calculate</button>
</div>
<div class="card">
<img src="https://visibletrucks.com.au/wp-content/uploads/2017/01/997-10-White-FLEXIBLE-1.png" alt="White1" style="width:100%">
<p class="price">$'.$Front1.'</p>
<p>3M™ Diamond Grade™ Conspicuity Marking Tape 983-10 White</p>
<button type="submit" name="add-to-cart" value="924" data-quantity="1" data-product_id="37153" class="single_add_to_cart_button button alt ajax_add_to_cart progress-btn add_to_cart_button">
<div class="btn" name="custom_price">Add to cart</div>
<div class="progress"></div>
<div class="checked"></div>
</button></p>
</div>
//计算按钮和逻辑
<?php
if(isset($_POST['calculate'])){
$V_Purpose = $_POST["V_Purpose"];
$V_AccessType = $_POST["V_AccessType"];
$V_Type = $_POST["V_Type"];
$V_TrailerType = $_POST["V_TrailerType"];
$count = 0;
$result = mysqli_query($con,"SELECT * FROM v_calculate WHERE V_Purpose='$V_Purpose' AND V_AccessType='$V_AccessType' AND V_Type='$V_Type' AND V_TrailerType='$V_TrailerType'");
if($result->num_rows > 0){
while($row = $result->fetch_assoc()){
$Front1 = 200 / $row['Front'];
$Front1 = number_format($Front1,2,'.',' ');
$Front1 = ceil($Front1);
$FrontCal = ceil($row['Front1']) * $Front1; ?>
在将计算值即$ FrontCal1发送到woocommerce中的购物车时,我需要帮助