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 d4861e2..f28b09c 100644 Binary files a/src/languages/retailcrm-es_ES.mo and b/src/languages/retailcrm-es_ES.mo differ diff --git a/src/languages/retailcrm-ru_RU.mo b/src/languages/retailcrm-ru_RU.mo index 5b37c1a..248c68e 100644 Binary files a/src/languages/retailcrm-ru_RU.mo and b/src/languages/retailcrm-ru_RU.mo differ