From 26efd7a510caaa15d8831cde46c5b9bd10d51f52 Mon Sep 17 00:00:00 2001 From: Sergey Krylov Date: Sat, 20 Mar 2021 22:32:44 +0300 Subject: [PATCH] working mailing --- functions.php | 85 +++++++++++++++++++++- parts/landings/graduation/callback.php | 2 +- parts/landings/graduation/offer-packet.php | 6 +- parts/landings/graduation/offers.php | 24 +++--- src/js/components/graduation.js | 42 ++++++++++- templates/graduation.php | 1 + 6 files changed, 139 insertions(+), 21 deletions(-) diff --git a/functions.php b/functions.php index 784bb52..4cd47c9 100644 --- a/functions.php +++ b/functions.php @@ -5,12 +5,19 @@ add_filter( 'nav_menu_submenu_css_class', 'change_wp_nav_menu', 10, 3 ); add_action( 'init', 'register_armanty_types' ); add_theme_support( 'post-thumbnails' ); + add_action( 'wp_ajax_send_mail', 'send_mail'); add_action( 'wp_ajax_nopriv_send_mail', 'send_mail'); + add_action( 'wp_ajax_send_main_form', 'send_main_form'); add_action( 'wp_ajax_nopriv_send_main_form', 'send_main_form'); + add_action( 'wp_ajax_send_callback', 'send_callback'); add_action( 'wp_ajax_nopriv_send_callback', 'send_callback'); + + add_action( 'wp_ajax_graduation_callback', 'graduation_callback'); + add_action( 'wp_ajax_nopriv_graduation_callback', 'graduation_callback'); + add_action( 'admin_menu', 'remove_menus' ); // Удаляем ненужные пункты в консоли WordPress @@ -70,7 +77,7 @@ function armanty_get_scripts(){ wp_enqueue_script('jquery'); wp_enqueue_script( 'jqmask', get_template_directory_uri( ) . '/assets/libs/jQuery-Mask-Plugin-master/dist/jquery.mask.min.js', ['jquery'], null, true); - + if (!is_page_template('templates/graduation.php')) { wp_enqueue_script( 'poper', get_template_directory_uri( ) . '/assets/libs/bootstrap-4.4.1-dist/js/popper.min.js', ['jquery'], null, true); wp_enqueue_script( 'bootstrap', get_template_directory_uri( ) . '/assets/libs/bootstrap-4.4.1-dist/js/bootstrap.bundle.min.js', ['jquery'], null, true); @@ -429,11 +436,85 @@ function send_callback(){ remove_all_filters( 'wp_mail_from_name' ); $headers = array( - 'From: Armanty Quest ', + 'From: Armanty Quest ', 'content-type: text/html', ); wp_mail( $to, $subject, $message, $headers ); wp_die(); +} + +function graduation_callback(){ + date_default_timezone_set('Europe/Moscow'); + + $name = $_POST['name']; + $phone = $_POST['phone']; + $packetName = $_POST['packetName']; + $date = date('m/d/Y h:i:s a', time()); + + $to = get_option('admin_email'); + $subject = 'Требуется перезвонить (Выпускной)'; + $message = 'Имя: ' . $name . '
' . + 'Телефон: ' . $phone . '
'; + if ($packetName) $message = $message . 'Пакет: ' . $packetName . '
'; + $message = $message . 'Время отправки: ' . $date . '
'; + + + // удалим фильтры, которые могут изменять заголовок $headers + remove_all_filters( 'wp_mail_from' ); + remove_all_filters( 'wp_mail_from_name' ); + + $headers = array( + 'From: Armanty Quest ', + 'content-type: text/html', + ); + + wp_mail( $to, $subject, $message, $headers ); + wp_die(); +} + +/** + * Like get_template_part() put lets you pass args to the template file + * Args are available in the tempalte as $template_args array + * @param string filepart + * @param mixed wp_args style argument list + */ + function hm_get_template_part( $file, $template_args = array(), $cache_args = array() ) { + $template_args = wp_parse_args( $template_args ); + $cache_args = wp_parse_args( $cache_args ); + if ( $cache_args ) { + foreach ( $template_args as $key => $value ) { + if ( is_scalar( $value ) || is_array( $value ) ) { + $cache_args[$key] = $value; + } else if ( is_object( $value ) && method_exists( $value, 'get_id' ) ) { + $cache_args[$key] = call_user_method( 'get_id', $value ); + } + } + if ( ( $cache = wp_cache_get( $file, serialize( $cache_args ) ) ) !== false ) { + if ( ! empty( $template_args['return'] ) ) + return $cache; + echo $cache; + return; + } + } + $file_handle = $file; + do_action( 'start_operation', 'hm_template_part::' . $file_handle ); + if ( file_exists( get_stylesheet_directory() . '/' . $file . '.php' ) ) + $file = get_stylesheet_directory() . '/' . $file . '.php'; + elseif ( file_exists( get_template_directory() . '/' . $file . '.php' ) ) + $file = get_template_directory() . '/' . $file . '.php'; + ob_start(); + $return = require( $file ); + $data = ob_get_clean(); + do_action( 'end_operation', 'hm_template_part::' . $file_handle ); + if ( $cache_args ) { + wp_cache_set( $file, $data, serialize( $cache_args ), 3600 ); + } + if ( ! empty( $template_args['return'] ) ) + if ( $return === false ) + return false; + else + return $data; + echo $data; } \ No newline at end of file diff --git a/parts/landings/graduation/callback.php b/parts/landings/graduation/callback.php index 438393b..bb9347c 100644 --- a/parts/landings/graduation/callback.php +++ b/parts/landings/graduation/callback.php @@ -4,7 +4,7 @@

Мы позвоним

Оставьте номер телефона для заказа выпускного

-
+ diff --git a/parts/landings/graduation/offer-packet.php b/parts/landings/graduation/offer-packet.php index babf86d..74080c8 100644 --- a/parts/landings/graduation/offer-packet.php +++ b/parts/landings/graduation/offer-packet.php @@ -1,12 +1,12 @@
-

-

₽ / человек

+

+

₽ / человек

  • - 'Базовый', - price => 900, - description => ['1 квест', '3 часа лофта', 'Украшение шарами', 'Аниматор', 'Диплом выпускника', '2 проститутки', '3 грамма кокаина и гашиша'] + 'Базовый', + 'price' => 900, + 'description' => ['1 квест', '3 часа лофта', 'Украшение шарами', 'Аниматор', 'Диплом выпускника', '2 проститутки', '3 грамма кокаина и гашиша'] )); ?>
    - 'Стандарт', - price => 1390, - description => ['2 квест', '3 часа лофта', 'Украшение шарами', 'Аниматор', 'Диплом выпускника'] + 'Стандарт', + 'price' => 1390, + 'description' => ['2 квест', '3 часа лофта', 'Украшение шарами', 'Аниматор', 'Диплом выпускника'] )); ?>
    - 'VIP', - price => 2490, - description => ['2 квест', '3 часа лофта', 'Украшение шарами', 'Аниматор', 'Диплом выпускника'] + 'VIP', + 'price' => 2490, + 'description' => ['2 квест', '3 часа лофта', 'Украшение шарами', 'Аниматор', 'Диплом выпускника'] )); ?>
diff --git a/src/js/components/graduation.js b/src/js/components/graduation.js index d5488b0..b76936d 100644 --- a/src/js/components/graduation.js +++ b/src/js/components/graduation.js @@ -1,6 +1,7 @@ $(document).ready(function () { - // Constansts + // Vars const TIME_FOR_SCROLL = 1000; + let packetName = ''; // Buttons const mainBtn = document.getElementById('main-btn'); @@ -13,21 +14,35 @@ $(document).ready(function () { const nameInput = document.querySelector('form #name'); // Blocks const formBlock = document.querySelector('.graduation__block.callback'); - const descriptionBlock = document.querySelector('.description') + const descriptionBlock = document.querySelector('.description'); + const orderModal = document.querySelector('.order-modal'); + const orderModalOverlay = document.querySelector('.order-modal__overlay') // Add event listeners toFormBtns.forEach(x => x.addEventListener('click', btnClickHandler.bind(null, formBlock))); getMoreBtn.addEventListener('click', scrollToElem.bind(null, descriptionBlock)); callbackBtn.addEventListener('click', submitForm); + orderModalOverlay.addEventListener('click', overlayHandler); //Handlers - function btnClickHandler(elem) { + function btnClickHandler(elem, e) { scrollToElem(elem); + + const packet = e.target.closest('.graduation__packet'); + if (packet) { + const some = packet.querySelector('h3') + packetName = some.textContent; + } + phoneInput.focus(); } + function overlayHandler() { + $(orderModal).hide(); + } + // Function with jQuery $(phoneInput).mask('+7 (000) 000-00-00'); @@ -47,7 +62,28 @@ $(document).ready(function () { if (!name || !phone) return; + const formData = {name, phone,} + if (packetName) formData.packetName = packetName; + const action = formBlock.querySelector('form').getAttribute('action'); + //AJAX send + $.ajax({ + url: action, + type: 'POST', + data: formData, + success: function (response) { + $(orderModal).show(); + + nameInput.value = '' + phoneInput.value = '' + packetName = '' + }, + error: function(request, txtstatus, errorThrown){ + console.error(request); + console.error(txtstatus); + console.error(errorThrown); + } + }); } }) diff --git a/templates/graduation.php b/templates/graduation.php index cbd8195..5194441 100644 --- a/templates/graduation.php +++ b/templates/graduation.php @@ -12,5 +12,6 @@ get_template_part('parts/landings/graduation/offers'); get_template_part('parts/landings/graduation/why'); get_template_part('parts/landings/graduation/callback'); + get_template_part('parts/home/order-modal'); get_template_part('parts/landings/graduation/footer'); ?> \ No newline at end of file