Bonjour,
Je souhaite ajouter un coefficient à mon calendrier de réservation de matériel pour mes clients
En fonction du nombres de jour de location, un coefficient s'applique:
je souhaite ajouter cela en php (Pouvez-vous me fournir un code php):
Si le nombre de jour est égale à 1, on applique le coeff 1
Si le nombre de jour est égale à 2, on applique le coeff 2
Si le nombre de jour est égale à 3, on applique le coeff 3
etc.....
$coeff1 = 1;
$coeff2 = 1.5;
$coeff3 = 2;
$coeff4 = 2.3;
$coeff5 = 2.5;
$coeff6 = 2.75;
$coeff7 = 3;
$coeff8 = 3.3;
$coeff9 = 3.7;
$coeff10 = 4;
$coeff11 = 4.2;
$coeff12 = 4.4;
$coeff13 = 4.6;
$coeff14 = 4.8;
$coeff15 = 5;
$coeff16 = 5.2;
$coeff17 = 5.4;
$coeff18 = 5.6;
$coeff19 = 5.8;
$coeff20 = 6;
$coeff21 = 6.2;
$coeff22 = 6.4;
$coeff23 = 6.6;
$coeff24 = 6.8;
$coeff25 = 7;
$coeff26 = 7.2;
$coeff27 = 7.4;
$coeff28 = 7.6;
(Code php ou il faut ajouter la modif)
<?php
namespace EkipRent;
use \DateTime;
class EkipRent_CalcDuration {
public static function calcDay($producte_id=null,$start_date,$end_date) {
$pricePer = get_post_meta($producte_id,'_pricing_type',true);
$total = 0;
switch ($pricePer) {
case 'hourly_pricing':
$start_date = new DateTime($start_date);
$end_date = new DateTime($end_date);
$interval = $start_date->diff($end_date);
$total = $interval->format('%dDay %hh');
break;
case 'daily_pricing':
$datediff = strtotime($end_date) - strtotime($start_date);
$total = round($datediff / (60 * 60 * 24))."<span>".esc_html__(' jour','ekiprent')." </span>";
break;
case 'weekly_pricing':
$start_date = new DateTime($start_date);
$end_date = new DateTime($end_date);
$total = ceil($start_date->diff($end_date)->days/7)."<span>".esc_html__(' Semaine','ekiprent')." </span>";
break;
}
return $total;
}
public static function calcPice($producte_id,$start_date,$end_date, $price) {
$order_quantity = (isset($_POST['quantity'])) ? $_POST['quantity'] : 1;
$pricePer = get_post_meta($producte_id,'_pricing_type',true);
$datediff = strtotime($end_date) - strtotime($start_date);
$totalPrice = 0;
switch ($pricePer) {
case 'hourly_pricing':
$hours = floor(($datediff ) / (60*60) );
$totalPrice = $hours * $price * $order_quantity;
break;
case 'daily_pricing':
$coeff1 = 1;
$coeff2 = 1.5;
$coeff3 = 2;
$coeff4 = 2.3;
$coeff5 = 2.5;
$coeff6 = 2.75;
$coeff7 = 3;
$coeff8 = 3.3;
$coeff9 = 3.7;
$coeff10 = 4;
$coeff11 = 4.2;
$coeff12 = 4.4;
$coeff13 = 4.6;
$coeff14 = 4.8;
$coeff15 = 5;
$coeff16 = 5.2;
$coeff17 = 5.4;
$coeff18 = 5.6;
$coeff19 = 5.8;
$coeff20 = 6;
$coeff21 = 6.2;
$coeff22 = 6.4;
$coeff23 = 6.6;
$coeff24 = 6.8;
$coeff25 = 7;
$coeff26 = 7.2;
$coeff27 = 7.4;
$coeff28 = 7.6;
$total_days = round($datediff / (60 * 60 * 24));
$totalPrice = $total_days * $price * $order_quantity;
break;
case 'weekly_pricing':
$start_date = new DateTime($start_date);
$end_date = new DateTime($end_date);
$total_week = ceil($start_date->diff($end_date)->days/7);
$totalPrice = $total_week * $price * $order_quantity;
break;
}
return $totalPrice;
}
}
Merci par avance !
En espérant trouver de l'aide !