You are here

function rooms_periodic_pricing_rooms_price_modifier_alter in Rooms - Drupal Booking for Hotels, B&Bs and Vacation Rentals 7

Implements hook_rooms_price_modifier_alter().

File

modules/rooms_pricing/modules/rooms_periodic_pricing/rooms_periodic_pricing.module, line 128

Code

function rooms_periodic_pricing_rooms_price_modifier_alter(&$price_modifiers, $booking_info) {
  if (!isset($price_modifiers['rooms_periodic_pricing'])) {
    $unit = $booking_info['unit'];
    $end_date = $booking_info['end_date'];
    $start_date = $booking_info['start_date'];
    $weeks_months_days = rooms_periodic_pricing_calculate_weeks_months_days($start_date, $end_date);

    // If "Monthly discount" is set and the current period is greater than or equal to 28 days.
    if ($weeks_months_days['months'] > 0 && $unit->monthly_discount > 0) {

      // Add a new price modifier to decrease old price with monthly discount.
      $price_modifiers['rooms_periodic_pricing'] = array(
        '#type' => ROOMS_DYNAMIC_MODIFIER,
        '#quantity' => 1,
        '#op_type' => ROOMS_DECREASE,
        '#amount' => $unit->monthly_discount,
      );
    }
    elseif ($weeks_months_days['total_weeks'] > 0 && $unit->weekly_discount > 0) {

      // Add a new price modifier to decrease old price with weekly discount.
      $price_modifiers['rooms_periodic_pricing'] = array(
        '#type' => ROOMS_DYNAMIC_MODIFIER,
        '#quantity' => 1,
        '#op_type' => ROOMS_DECREASE,
        '#amount' => $unit->weekly_discount,
      );
    }
  }
}