让我们假设我们有这些变量。
// base shipping cost of product
$product_shipping_cost = 10;
// You can send 4 same products in the same pack with $product_shipping_cost
$product_shipping_interval_quantity = 4;
// Your current quantity in cart
$cart_quantity = 9;
// defined total shipping cost, should be in this case 30;
// because 9 in $cart quantity
$total_shipping_cost = 0;
在现实生活中应该如何工作?所以基本上我们有这个:
如何实现这样的公式?我试图
$total_shipping_cost = $product_shipping_cost * floor($cart_quantity/$product_shipping_interval_quantity)
但是它不起作用,它仅在4/8/12等不在5/9/13时才更改,并且在以下情况下不是以10开头:即购物车中有2个。
答案 0 :(得分:1)
使用天花板而不是地板:
$total_shipping_cost = $product_shipping_cost *
ceil($cart_quantity/$product_shipping_interval_quantity)