'', 'bookingData' => '', 'userData' => '' ); $data = array_merge($defaultData, $data); // Booking Data if (empty($data['bookingData'])) { $data['bookingData'] = false; } else { $data['bookingData'] = json_decode($data['bookingData'], true); $data['bookingId'] = $data['bookingData']['id']; } // User Data if (empty($data['userData'])) { $data['userData'] = false; } else { $data['userData'] = json_decode($data['userData'], true); } // Set Variables $this->bookingId = $data['bookingId']; $this->bookingData = $data['bookingData']; $this->userData = $data['userData']; } public function validBookingData() { if (empty($this->bookingId) || !$this->bookingData || empty($this->bookingData)) { return false; } return true; } public function validUserData() { return true; } // public function prepareOrderData() { if (!$this->bookingData) { return false; } $orderData = array( 'room_name' => '', 'room_price' => '', 'guests' => '', 'dates' => $this->bookingData['check_in'] . ' - ' . $this->bookingData['check_out'], 'total_price' => '$999', 'total_price_value' => '', 'total_price_currency' => '' ); // Room Data $roomData = Hotel_Content::roomItem($this->bookingData['room_id']); if (!$roomData) { return false; } $orderData['room_name'] = $roomData['name']; $orderData['room_price'] = $roomData['price']; $orderData['room_number'] = 0; $orderData['guest_number'] = 0; $orderData['guest'] = ''; // Guest if (!empty($this->bookingData['adults'])) { $orderData['guest'] .= $this->bookingData['adults'] . ' Adults, '; } if (!empty($this->bookingData['children'])) { $orderData['guest'] .= $this->bookingData['children'] . ' Children, '; } $orderData['guest'] = substr($orderData['guest'], 0, -2); // $orderSummary = $this->orderSummary(array( 'adults' => $this->bookingData['adults'], 'children' => $this->bookingData['children'], 'roomSize' => $roomData['guest'], 'price' => $roomData['price_value'], 'currency' => $roomData['currency'], 'checkInTime' => $this->bookingData['check_in_time'], 'checkOutTime' => $this->bookingData['check_out_time'] )); $orderData['rooms'] = $orderSummary['rooms']; $orderData['totalPrice'] = $orderSummary['price']; $orderData['totalPriceFormatted'] = $orderSummary['priceFormatted']; // return $orderData; } public function registerNewOrder() { if (!empty($_SESSION['booking-order-' . $this->bookingId])) { return false; } // $roomData = Hotel_Content::roomItem($this->bookingData['room_id']); $orderData = $this->orderSummary(array( 'adults' => $this->bookingData['adults'], 'children' => $this->bookingData['children'], 'roomSize' => $roomData['guest'], 'price' => $roomData['price_value'], 'currency' => $roomData['currency'], 'checkInTime' => $this->bookingData['check_in_time'], 'checkOutTime' => $this->bookingData['check_out_time'] )); // $orderSummary = array(); $orderSummary[] = array('header', 'Room Info'); $orderSummary[] = array('Room Name:', $roomData['name']); $orderSummary[] = array('Room Price:', $roomData['price']); // $orderSummary[] = array('header', 'Order Info'); $orderSummary[] = array('Check In Date:', $this->bookingData['check_in']); $orderSummary[] = array('Check Out Date:', $this->bookingData['check_out']); $orderSummary[] = array('Adults:', $this->bookingData['adults']); $orderSummary[] = array('Children:', $this->bookingData['children']); $orderSummary[] = array('Days:', $orderData['days']); $orderSummary[] = array('Rooms:', $orderData['rooms']); $orderSummary[] = array('Total Price:', $orderData['priceFormatted']); // $orderSummary[] = array('header', 'Client Data'); $orderSummary[] = array('First Name:', $this->userData['first_name']); $orderSummary[] = array('Last Name:', $this->userData['last_name']); $orderSummary[] = array('City:', $this->userData['city']); $orderSummary[] = array('ZIP / Postcode:', $this->userData['postcode']); $orderSummary[] = array('State:', $this->userData['state']); $orderSummary[] = array('Country:', $this->userData['country']); $orderSummary[] = array('Address Line 1:', $this->userData['address_line_1']); $orderSummary[] = array('Address Line 2:', $this->userData['address_line_2']); $orderSummary[] = array('Special Requirements:', $this->userData['requirements']); // $htmlMail = $this->orderMailHtml($orderSummary); wp_mail(Hotel_Content::getSetting('notify_email'), get_bloginfo('name') . ' / New Order', $htmlMail); // return true; } private function orderSummary($data) { $defaultData = array( 'adults' => '', 'children' => '', 'roomSize' => '', 'price' => '', 'currency' => '', 'checkInTime' => '', 'checkOutTime' => '' ); $data = array_merge($defaultData, $data); $data['adults'] *= 1; $data['children'] *= 1; $data['roomSize'] *= 1; $data['price'] *= 1; $data['checkInTime'] *= 1; $data['checkOutTime'] *= 1; // $guestSum = $data['adults'] + $data['children']; $roomNumber = ceil($guestSum / $data['roomSize']); // number of rooms per day $daysNumber = ceil(($data['checkOutTime'] - $data['checkInTime']) / (3600 * 24)); // (check out - check in) / days $totalPrice = $roomNumber * $data['price'] * $daysNumber; // return array( 'guest' => $guestSum, 'days' => $daysNumber, 'price' => $totalPrice, 'rooms' => $roomNumber, 'priceFormatted' => Hotel_Content::renderPrice($totalPrice, $data['currency']) ); } private function orderMailHtml($arr) { $html = ''; $html .= '

' . get_bloginfo('name') . ' / New Order

'; foreach ($arr as $e) { if ($e[0] == 'header') { $html .= '

' . $e[1] . '

'; } else { $html .= '

' . '' . $e[0] . '' . '' . $e[1] . '' . '

'; } } require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-base.php'); require_once(ABSPATH . 'wp-admin/includes/class-wp-filesystem-direct.php'); $filesystem = new WP_Filesystem_Direct(array()); $mail_path = __DIR__ .'/../_mail_structure.html'; $htmlStructure = $filesystem->get_contents($mail_path); $html = str_replace('{{content}}', $html, $htmlStructure); return $html; } }