1
0
mirror of synced 2025-02-21 01:13:13 +03:00

Add link on WhatsApp chat

This commit is contained in:
Dima Uryvskiy 2021-06-09 13:48:21 +03:00 committed by GitHub
parent d1d2037bf0
commit 948be17b92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 173 additions and 2 deletions

View File

@ -243,3 +243,31 @@ msgstr "Soporte a clientes corporativos"
msgid "Enabled"
msgstr "Habilitado"
msgid "Settings of WhatsApp"
msgstr "Ajustes de WhatsApp"
msgid "Activar WhatsApp"
msgstr "Активировать WhatsApp"
msgid "Activate this setting to activate WhatsApp on the website"
msgstr "Activa esta configuración para activar WhatsApp en la página web"
msgid "WhatsApp icon location"
msgstr "Ubicación del ícono de WhatsApp"
msgid "Place in the lower right corner of the website"
msgstr "Colocar en la esquina inferior derecha de la pagina web"
msgid "By default, WhatsApp icon is located in the lower left corner of the website"
msgstr "Por defecto, el ícono de WhatsApp se encuentra en la esquina inferior izquierda de la página web"
msgid "Enter your phone number"
msgstr "Introduce tu número de teléfono"
msgid "WhatsApp chat will be opened with this contact"
msgstr "Se abrirá una ventana de chat con este contacto en WhatsApp"
msgid "Introduce the correct phone number"
msgstr "Introduce el número de teléfono correcto"

View File

@ -252,3 +252,31 @@ msgstr "Поддержка корпоративных клиентов"
msgid "Enabled"
msgstr "Включено"
msgid "Settings of WhatsApp"
msgstr "Настройки WhatsApp"
msgid "Activate WhatsApp"
msgstr "Активировать WhatsApp"
msgid "Activate this setting to activate WhatsApp on the website"
msgstr "Активируйте эту настройку для активации WhatsApp на сайте"
msgid "WhatsApp icon location"
msgstr "Расположение иконки WhatsApp"
msgid "Place in the lower right corner of the website"
msgstr "Разместить в правом нижнем углу сайта"
msgid "By default, WhatsApp icon is located in the lower left corner of the website"
msgstr "По умолчанию иконка WhatsApp расположена в левом нижнем углу сайта"
msgid "Enter your phone number"
msgstr "Введите номер телефона"
msgid "WhatsApp chat will be opened with this contact"
msgstr "Будет открыт чат в WhatsApp с данным контактом"
msgid "Introduce the correct phone number"
msgstr "Введите корректный номер телефона"

View File

@ -0,0 +1,23 @@
.whatsapp-icon {
position: fixed;
left: 0;
bottom: 20px;
width: 60px;
height: 60px;
box-sizing: border-box;
}
.whatsapp-icon_left {
left: 32px;
right: auto;
}
.whatsapp-icon_right {
right: 32px;
left: auto;
}
.whatsapp-icon__icon {
width: 100%;
height: 100%;
}

1
src/assets/css/whatsapp_icon.min.css vendored Normal file
View File

@ -0,0 +1 @@
.whatsapp-icon{position:fixed;left:0;bottom:20px;width:60px;height:60px;box-sizing:border-box}.whatsapp-icon_left{left:32px;right:auto}.whatsapp-icon_right{right:32px;left:auto}.whatsapp-icon__icon{width:100%;height:100%}

View File

@ -438,7 +438,40 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
);
}
/*
/**
* WhatsApp options
*/
$this->form_fields[] = array(
'title' => __('Settings of WhatsApp', 'retailcrm'),
'type' => 'heading',
'description' => '',
'id' => 'whatsapp_options'
);
$this->form_fields['whatsapp_active'] = array(
'label' => __('Activate WhatsApp', 'retailcrm'),
'title' => __('WhatsApp', 'retailcrm'),
'class' => 'checkbox',
'type' => 'checkbox',
'description' => __('Activate this setting to activate WhatsApp on the website', 'retailcrm')
);
$this->form_fields['whatsapp_location_icon'] = array(
'label' => __('Place in the lower right corner of the website', 'retailcrm'),
'title' => __('WhatsApp icon location', 'retailcrm'),
'class' => 'checkbox',
'type' => 'checkbox',
'description' => __('By default, WhatsApp icon is located in the lower left corner of the website', 'retailcrm')
);
$this->form_fields['whatsapp_number'] = array(
'title' => __('Enter your phone number', 'retailcrm'),
'class' => '',
'type' => 'text',
'description' => __('WhatsApp chat will be opened with this contact', 'retailcrm')
);
/**
* Generate icml file
*/
$this->form_fields[] = array(
@ -669,6 +702,32 @@ abstract class WC_Retailcrm_Abstracts_Settings extends WC_Integration
return $value;
}
/**
* Validate whatsapp phone number
*
* @param string $key
* @param string $value
*
* @return string
*/
public function validate_whatsapp_number_field($key, $value)
{
$post = $this->get_post_data();
if (!empty($post['woocommerce_integration-retailcrm_whatsapp_active'])) {
$phoneNumber = preg_replace('/[^+0-9]/', '', $value);
if (empty($value) || strlen($value) > 25 || strlen($phoneNumber) !== strlen($value)) {
WC_Admin_Settings::add_error(esc_html__('Introduce the correct phone number', 'retailcrm'));
$value = '';
}
}
return $value;
}
/**
* Scritp show|hide block settings
*/

View File

@ -93,6 +93,8 @@ if (!class_exists('WC_Retailcrm_Base')) {
add_action('wp_print_scripts', array($this, 'initialize_analytics'), 98);
add_action('wp_print_scripts', array($this, 'initialize_daemon_collector'), 99);
add_action('wp_print_scripts', array($this, 'initialize_online_assistant'), 101);
add_action('wp_enqueue_scripts', array($this, 'include_whatsapp_icon_style'), 101);
add_action('wp_print_footer_scripts', array($this, 'initialize_whatsapp'), 101);
add_action('wp_print_footer_scripts', array($this, 'send_analytics'), 99);
add_action('woocommerce_new_order', array($this, 'create_order'), 11, 1);
@ -375,7 +377,7 @@ if (!class_exists('WC_Retailcrm_Base')) {
echo '';
}
}
/**
* Initialize online consultant
*/
@ -386,6 +388,36 @@ if (!class_exists('WC_Retailcrm_Base')) {
}
}
/**
* Include style for WhatsApp icon
*/
public function include_whatsapp_icon_style()
{
wp_register_style('whatsapp_icon_style', plugins_url() . '/woo-retailcrm/assets/css/whatsapp_icon.min.css', false, '0.1');
wp_enqueue_style('whatsapp_icon_style');
}
/**
* Initialize WhatsApp
*/
public function initialize_whatsapp()
{
if ($this->get_option('whatsapp_active') === 'yes' && !is_admin() && !is_wplogin()) {
$phoneNumber = $this->get_option('whatsapp_number');
$positionIcon = $this->get_option('whatsapp_location_icon') === 'yes' ? 'right' : 'left';
$whatsAppHtml = '<div class="whatsapp-icon whatsapp-icon_%s">
<a class="whatsapp-icon__link" href="https://api.whatsapp.com/send/?phone=%s&text&app_absent=0" target="_blank">
<svg class="whatsapp-icon__icon" fill="none" viewbox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M12 24c6.627 0 12-5.373 12-12S18.627 0 12 0 0 5.373 0 12s5.373 12 12 12z" fill="#25D366"/><path d="M12.396 18.677h-.003a7.13 7.13 0 01-3.41-.869L5.2 18.8l1.013-3.697a7.123 7.123 0 01-.953-3.567C5.262 7.6 8.463 4.4 12.396 4.4c1.909.001 3.7.744 5.047 2.093a7.093 7.093 0 012.088 5.048c-.001 3.934-3.201 7.134-7.135 7.136zm-3.238-2.16l.217.128c.91.54 1.954.826 3.018.827h.003a5.94 5.94 0 005.93-5.931 5.895 5.895 0 00-1.735-4.196 5.89 5.89 0 00-4.193-1.74 5.94 5.94 0 00-5.933 5.931c0 1.12.313 2.212.907 3.156l.14.225-.599 2.188 2.245-.588zm6.588-3.44c.125.06.209.101.245.161.044.074.044.431-.104.848-.15.416-.861.796-1.204.848a2.443 2.443 0 01-1.123-.071 10.223 10.223 0 01-1.016-.376c-1.672-.721-2.801-2.341-3.015-2.648l-.031-.044-.002-.002c-.094-.126-.726-.97-.726-1.842 0-.821.403-1.252.589-1.45l.035-.038a.655.655 0 01.475-.223c.12 0 .238.001.342.007h.04c.104 0 .233-.001.361.306.05.118.121.293.197.478.154.373.323.786.353.846.044.089.074.193.015.312l-.025.05c-.045.092-.078.159-.153.247l-.092.11c-.061.075-.123.15-.176.203-.09.089-.182.185-.078.364.104.178.462.762.992 1.235.57.508 1.065.723 1.316.832.049.02.088.038.118.053.178.089.282.074.386-.045.104-.119.446-.52.564-.7.12-.178.238-.148.402-.088.163.06 1.04.49 1.218.58l.097.048z" fill="#FDFDFD"/></svg>
</a>
</div>';
echo sprintf($whatsAppHtml, $positionIcon, $phoneNumber);
}
}
/**
* Get retailcrm api client
*

Binary file not shown.

Binary file not shown.