计算具有不同定价 wordpress 和 woocommerce 时期的租金价格

Calculate price of rental with different periods of pricing wordpress & woocommerce

您好,我正在一家 woocommerce 汽车租赁店工作,我有以下问题需要解决。 鉴于以下情况: 一位客户来租车,日期为 10 月 29 日 11:00 至 11 月 12 日 11:00,总共租了 15 天。 租车的基本价格为 17 euros/day,10 月需额外支付 5 euros/day,11 月为 17 euros/day,额外需支付 10 euros/day。 所以现在我有以下显示相同示例的转储:

Base Price: 17
Array
(
    [10] => Array
        (
            [fee] => 5.00
            [days] => 3
        )

    [11] => Array
        (
            [fee] => 10.00
            [days] => 12
        )

)

当我计算时,我在 10 月 29 日至 10 月 31 日的第一期获得 66 欧元,在 11 月 1 日至 11 月 12 日的第一期获得 324 欧元,总计 390 欧元。 如果我将平均价格设为 390 / 15,然后将其设置为汽车价格,则总价将不正确。 我怎样才能改变 wocommerce 计算总数的方式来计算汽车的价格 + 其他租赁选项。 ?

这是一个真正的基本示例

$price = '17.00';
$period_range = array(
    '10' => array(
        'fee' => 5.00,
        'days' => 3
    ),
    '11' => array(
        'fee' => 10.00,
        'days' => 12
    )
);
$charge = array();
foreach($period_range as $range) {
    $charge[] = round($range['fee'] * $range['days']);
}

$total = array_sum($charge) + $price;
echo $total;
//this will return 152