为购物车数量的定义迭代添加运费的公式

Formula to add shipping cost for defined iteration of cart quantity

假设我们有这些变量。

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

但它不起作用,它仅在 2012 年 4 月 8 日等而不是 2013 年 5 月 9 日发生变化,并且它不是以 10 开头,即:购物车中有 2 件。

使用 ceil 而不是 floor:

$total_shipping_cost = $product_shipping_cost * 
   ceil($cart_quantity/$product_shipping_interval_quantity)