function wpinventory_process_reserve($data) { $to_email = wpinventory_get_config('reserve_email'); if (!$to_email) { $to_email = get_option('admin_email'); } $subject = WPIMCore::__('An item has been reserved from') . ' ' . get_bloginfo('site_name'); $message = ''; $fields = array('inventory_number', 'inventory_serial', 'inventory_name'); $fields = apply_filters('wpim_reserve_item_fields', $fields); $item_title = WPIMCore::__('Item Details'); $item_title = apply_filters('wpim_reserve_title_item_details', $item_title); $message .= PHP_EOL . $item_title; $inventory_display = wpinventory_get_display_settings('detail'); if (!empty($data['inventory_id'])) { $loop = new WPIMLoop(array('inventory_id' => $data['inventory_id'])); while ($loop->have_items()) { $loop->the_item(); foreach ($inventory_display as $field) { $message .= PHP_EOL . $loop->get_label($field) . ': ' . $loop->get_field($field); } } } $reservation_title = WPIMCore::__('Reservation Details'); $reservation_title = apply_filters('wpim_reserve_title_reservation_details', $reservation_title); $message .= PHP_EOL . PHP_EOL . $reservation_title; $exclude = array('inventory_id'); $exclude = apply_filters('wpim_reserve_exclude_form_fields', $exclude); $args = wpinventory_get_reserve_config(); foreach ($data as $field => $d) { if (!in_array($field, $exclude) && $args['display_' . $field]) { $message .= PHP_EOL . $d['label'] . ': ' . $d['value']; } } $subject = apply_filters('wpim_reserve_email_subject', $subject); $message = apply_filters('wpim_reserve_email_message', $message); $status = FALSE; $test_mode = FALSE; if ($test_mode) { echo '<br>== E-Mail output (in test mode) ==<br>'; echo '<pre>'; echo 'To: ' . $to_email . PHP_EOL; echo 'Subject: ' . $subject . PHP_EOL; echo 'Message:' . PHP_EOL; echo $message; echo '</pre>'; } $success = wp_mail($to_email, $subject, $message); if (!$success) { return WPIMCore::__('There was an issue sending your e-mail. Please try again later.'); } else { if (wpinventory_get_config('reserve_decrement')) { $wpim_item = new WPIMItem(); $wpim_item->save_reserve($data['inventory_id'], $data['quantity']['value']); do_action('wpim_reserve_sent', $data['inventory_id'], $data, $subject, $message); $status = TRUE; } } $send_confirmation = wpinventory_get_config('reserve_confirmation'); if ($send_confirmation) { // Grab e-mail from the form $confirm_email = $data['email']['value']; // If the user is logged in, use that e-mail if (is_user_logged_in()) { $current_user = wp_get_current_user(); $confirm_email = $current_user->user_email; } $subject = apply_filters('wpim_reserve_confirmation_email_subject', $subject); $message = apply_filters('wpim_reserve_confirmation_email_message', $message); if ($test_mode) { echo '<br>== E-Mail Confirmation output (in test mode) ==<br>'; echo '<pre>'; echo 'To: ' . $confirm_email . PHP_EOL; echo 'Subject: ' . $subject . PHP_EOL; echo 'Message:' . PHP_EOL; echo $message; echo '</pre>'; } $success = wp_mail($confirm_email, $subject, $message); if (!$success) { return WPIMCore::__('There was an issue sending the confirmation e-mail. Please try again later.'); } else { do_action('wpim_reserve_confirmation_sent', $data['inventory_id'], $data, $subject, $message); $status = TRUE; } } return $status; }