From 948be17b92189777b70476246f61a693498a46b5 Mon Sep 17 00:00:00 2001 From: Dima Uryvskiy Date: Wed, 9 Jun 2021 13:48:21 +0300 Subject: [PATCH] Add link on WhatsApp chat --- resources/pot/retailcrm-es_ES.pot | 28 ++++++++ resources/pot/retailcrm-ru_RU.pot | 28 ++++++++ src/assets/css/whatsapp_icon.css | 23 +++++++ src/assets/css/whatsapp_icon.min.css | 1 + .../class-wc-retailcrm-abstracts-settings.php | 61 +++++++++++++++++- src/include/class-wc-retailcrm-base.php | 34 +++++++++- src/languages/retailcrm-es_ES.mo | Bin 6975 -> 8012 bytes src/languages/retailcrm-ru_RU.mo | Bin 8628 -> 9782 bytes 8 files changed, 173 insertions(+), 2 deletions(-) create mode 100644 src/assets/css/whatsapp_icon.css create mode 100644 src/assets/css/whatsapp_icon.min.css diff --git a/resources/pot/retailcrm-es_ES.pot b/resources/pot/retailcrm-es_ES.pot index e2a508f..438ca7b 100644 --- a/resources/pot/retailcrm-es_ES.pot +++ b/resources/pot/retailcrm-es_ES.pot @@ -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" + diff --git a/resources/pot/retailcrm-ru_RU.pot b/resources/pot/retailcrm-ru_RU.pot index 4d73769..5f9f9ae 100644 --- a/resources/pot/retailcrm-ru_RU.pot +++ b/resources/pot/retailcrm-ru_RU.pot @@ -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 "Введите корректный номер телефона" + diff --git a/src/assets/css/whatsapp_icon.css b/src/assets/css/whatsapp_icon.css new file mode 100644 index 0000000..4dcad66 --- /dev/null +++ b/src/assets/css/whatsapp_icon.css @@ -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%; +} diff --git a/src/assets/css/whatsapp_icon.min.css b/src/assets/css/whatsapp_icon.min.css new file mode 100644 index 0000000..0d37f09 --- /dev/null +++ b/src/assets/css/whatsapp_icon.min.css @@ -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%} \ No newline at end of file diff --git a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php index bb54cac..01dfdd0 100644 --- a/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php +++ b/src/include/abstracts/class-wc-retailcrm-abstracts-settings.php @@ -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 */ diff --git a/src/include/class-wc-retailcrm-base.php b/src/include/class-wc-retailcrm-base.php index fa1572e..036352f 100644 --- a/src/include/class-wc-retailcrm-base.php +++ b/src/include/class-wc-retailcrm-base.php @@ -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 = '
+ + + +
'; + + echo sprintf($whatsAppHtml, $positionIcon, $phoneNumber); + } + } + + /** * Get retailcrm api client * diff --git a/src/languages/retailcrm-es_ES.mo b/src/languages/retailcrm-es_ES.mo index d4861e2ce4cbce11d49381b4b521334fd44ff2ef..f28b09cfed75c2f20ae9f82ff20e7b76a8b1c2be 100644 GIT binary patch delta 2713 zcmZ|PTWl0n9LMp~7D{cowUu_kB2y4WXv;-tDK|?21w^P^ikC#Q-A>z)Wv5JMTQR^Q zi9YdAv!W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