working mailing

This commit is contained in:
Sergey Krylov 2021-03-20 22:32:44 +03:00
parent 1fa9461f62
commit 26efd7a510
6 changed files with 139 additions and 21 deletions

View File

@ -5,12 +5,19 @@
add_filter( 'nav_menu_submenu_css_class', 'change_wp_nav_menu', 10, 3 ); add_filter( 'nav_menu_submenu_css_class', 'change_wp_nav_menu', 10, 3 );
add_action( 'init', 'register_armanty_types' ); add_action( 'init', 'register_armanty_types' );
add_theme_support( 'post-thumbnails' ); add_theme_support( 'post-thumbnails' );
add_action( 'wp_ajax_send_mail', 'send_mail'); add_action( 'wp_ajax_send_mail', 'send_mail');
add_action( 'wp_ajax_nopriv_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_send_main_form', 'send_main_form');
add_action( 'wp_ajax_nopriv_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_send_callback', 'send_callback');
add_action( 'wp_ajax_nopriv_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' ); add_action( 'admin_menu', 'remove_menus' );
// Удаляем ненужные пункты в консоли WordPress // Удаляем ненужные пункты в консоли WordPress
@ -70,7 +77,7 @@ function armanty_get_scripts(){
wp_enqueue_script('jquery'); 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); 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')) { 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( '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); 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' ); remove_all_filters( 'wp_mail_from_name' );
$headers = array( $headers = array(
'From: Armanty Quest <me@example.net>', 'From: Armanty Quest <admin@armanty-quests.ru>',
'content-type: text/html', 'content-type: text/html',
); );
wp_mail( $to, $subject, $message, $headers ); wp_mail( $to, $subject, $message, $headers );
wp_die(); 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 = '<b>Имя:</b> ' . $name . '<br/>' .
'<b>Телефон:</b> ' . $phone . '<br/>';
if ($packetName) $message = $message . '<b>Пакет:</b> ' . $packetName . '<br/>';
$message = $message . '<b>Время отправки:</b> ' . $date . '<br/>';
// удалим фильтры, которые могут изменять заголовок $headers
remove_all_filters( 'wp_mail_from' );
remove_all_filters( 'wp_mail_from_name' );
$headers = array(
'From: Armanty Quest <admin@armanty-quests.ru>',
'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;
} }

View File

@ -4,7 +4,7 @@
<h2>Мы позвоним</h2> <h2>Мы позвоним</h2>
<p>Оставьте номер телефона для заказа выпускного</p> <p>Оставьте номер телефона для заказа выпускного</p>
</div> </div>
<form action="callback.php" method="POST"> <form action="<?php echo admin_url('admin-ajax.php?action=graduation_callback')?>" method="POST">
<label> <label>
<input type="text" placeholder="Введите телефон" id="phone"> <input type="text" placeholder="Введите телефон" id="phone">
</label> </label>

View File

@ -1,12 +1,12 @@
<div class="graduation__packet"> <div class="graduation__packet">
<div class="text"> <div class="text">
<h3><?php echo $args[title] ?></h2> <h3><?php echo $template_args[title] ?></h2>
<p><span><?php echo $args[price] ?></span> ₽ / <span>человек</span></p> <p><span><?php echo $template_args[price] ?></span> ₽ / <span>человек</span></p>
</div> </div>
<div class="packet_description"> <div class="packet_description">
<ul> <ul>
<?php <?php
foreach ($args[description] as &$point) { if ($template_args['description']) foreach ($template_args['description'] as &$point) {
?> ?>
<li><?php echo $point; ?></li> <li><?php echo $point; ?></li>
<?php <?php

View File

@ -7,25 +7,25 @@
<div class="row packets center"> <div class="row packets center">
<div class="col-4 packet"> <div class="col-4 packet">
<?php get_template_part('parts/landings/graduation/offer-packet', null, array( <?php hm_get_template_part('parts/landings/graduation/offer-packet', array(
title => 'Базовый', 'title' => 'Базовый',
price => 900, 'price' => 900,
description => ['1 квест', '3 часа лофта', 'Украшение шарами', 'Аниматор', 'Диплом выпускника', '2 проститутки', '3 грамма кокаина и гашиша'] 'description' => ['1 квест', '3 часа лофта', 'Украшение шарами', 'Аниматор', 'Диплом выпускника', '2 проститутки', '3 грамма кокаина и гашиша']
)); ?> )); ?>
</div> </div>
<div class="col-4 packet"> <div class="col-4 packet">
<?php get_template_part('parts/landings/graduation/offer-packet', null, array( <?php hm_get_template_part('parts/landings/graduation/offer-packet', array(
title => 'Стандарт', 'title' => 'Стандарт',
price => 1390, 'price' => 1390,
description => ['2 квест', '3 часа лофта', 'Украшение шарами', 'Аниматор', 'Диплом выпускника'] 'description' => ['2 квест', '3 часа лофта', 'Украшение шарами', 'Аниматор', 'Диплом выпускника']
)); ?> )); ?>
</div> </div>
<div class="col-4 packet"> <div class="col-4 packet">
<?php get_template_part('parts/landings/graduation/offer-packet', null, array( <?php hm_get_template_part('parts/landings/graduation/offer-packet', array(
title => 'VIP', 'title' => 'VIP',
price => 2490, 'price' => 2490,
description => ['2 квест', '3 часа лофта', 'Украшение шарами', 'Аниматор', 'Диплом выпускника'] 'description' => ['2 квест', '3 часа лофта', 'Украшение шарами', 'Аниматор', 'Диплом выпускника']
)); ?> )); ?>
</div> </div>
</div> </div>

View File

@ -1,6 +1,7 @@
$(document).ready(function () { $(document).ready(function () {
// Constansts // Vars
const TIME_FOR_SCROLL = 1000; const TIME_FOR_SCROLL = 1000;
let packetName = '';
// Buttons // Buttons
const mainBtn = document.getElementById('main-btn'); const mainBtn = document.getElementById('main-btn');
@ -13,21 +14,35 @@ $(document).ready(function () {
const nameInput = document.querySelector('form #name'); const nameInput = document.querySelector('form #name');
// Blocks // Blocks
const formBlock = document.querySelector('.graduation__block.callback'); 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 // Add event listeners
toFormBtns.forEach(x => x.addEventListener('click', btnClickHandler.bind(null, formBlock))); toFormBtns.forEach(x => x.addEventListener('click', btnClickHandler.bind(null, formBlock)));
getMoreBtn.addEventListener('click', scrollToElem.bind(null, descriptionBlock)); getMoreBtn.addEventListener('click', scrollToElem.bind(null, descriptionBlock));
callbackBtn.addEventListener('click', submitForm); callbackBtn.addEventListener('click', submitForm);
orderModalOverlay.addEventListener('click', overlayHandler);
//Handlers //Handlers
function btnClickHandler(elem) { function btnClickHandler(elem, e) {
scrollToElem(elem); scrollToElem(elem);
const packet = e.target.closest('.graduation__packet');
if (packet) {
const some = packet.querySelector('h3')
packetName = some.textContent;
}
phoneInput.focus(); phoneInput.focus();
} }
function overlayHandler() {
$(orderModal).hide();
}
// Function with jQuery // Function with jQuery
$(phoneInput).mask('+7 (000) 000-00-00'); $(phoneInput).mask('+7 (000) 000-00-00');
@ -47,7 +62,28 @@ $(document).ready(function () {
if (!name || !phone) return; if (!name || !phone) return;
const formData = {name, phone,}
if (packetName) formData.packetName = packetName;
const action = formBlock.querySelector('form').getAttribute('action');
//AJAX send //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);
}
});
} }
}) })

View File

@ -12,5 +12,6 @@
get_template_part('parts/landings/graduation/offers'); get_template_part('parts/landings/graduation/offers');
get_template_part('parts/landings/graduation/why'); get_template_part('parts/landings/graduation/why');
get_template_part('parts/landings/graduation/callback'); get_template_part('parts/landings/graduation/callback');
get_template_part('parts/home/order-modal');
get_template_part('parts/landings/graduation/footer'); get_template_part('parts/landings/graduation/footer');
?> ?>