should_render() ) { return; } $settings = Solutiontech_WhatsApp_Helpers::get_settings(); wp_enqueue_style( 'st-wa-frontend-css', ST_WA_URL . 'assets/css/st-frontend.css', array(), ST_WA_VERSION ); // Dynamic CSS for custom colors and offsets. $custom_css = $this->generate_custom_css( $settings ); wp_add_inline_style( 'st-wa-frontend-css', $custom_css ); $frontend_deps = array(); if ( '1' === $settings['qr_enabled'] ) { wp_enqueue_script( 'st-wa-qrcode', ST_WA_URL . 'assets/js/qrcode.min.js', array(), '1.4.4', true ); $frontend_deps[] = 'st-wa-qrcode'; } wp_enqueue_script( 'st-wa-frontend-js', ST_WA_URL . 'assets/js/st-frontend.js', $frontend_deps, ST_WA_VERSION, true ); $is_online = Solutiontech_WhatsApp_Helpers::is_within_business_hours( $settings ); $default_message = Solutiontech_WhatsApp_Helpers::replace_tags( $settings['default_message'] ); $direct_url = Solutiontech_WhatsApp_Helpers::build_whatsapp_url( $settings['phone_number'], $default_message ); // Localize parameters for JS tracking, triggers, badge, sound, and QR. wp_localize_script( 'st-wa-frontend-js', 'stWaConfig', array( 'trackGA4' => '1' === $settings['track_ga4'], 'trackPixel' => '1' === $settings['track_pixel'], 'defaultMessage' => $default_message, 'phone' => Solutiontech_WhatsApp_Helpers::clean_phone( $settings['phone_number'] ), 'isPopup' => '1' === $settings['popup_enabled'], 'badgeEnabled' => '1' === $settings['badge_enabled'], 'badgeDelay' => absint( $settings['badge_delay'] ), 'soundEnabled' => '1' === $settings['sound_enabled'], 'autoOpenDelay' => absint( $settings['auto_open_delay'] ), 'scrollTrigger' => '1' === $settings['scroll_trigger'], 'scrollPercent' => absint( $settings['scroll_percent'] ), 'exitIntent' => '1' === $settings['exit_intent'], 'qrEnabled' => '1' === $settings['qr_enabled'], 'qrTargetUrl' => esc_url_raw( $direct_url ), 'gdprEnabled' => '1' === $settings['gdpr_enabled'], 'isOnline' => $is_online, 'strings' => array( 'gdprWarning' => __( 'Por favor, acepta la política de privacidad para continuar.', 'solutiontech-customer-chat' ), 'scanWithPhone' => __( 'Escanea el código QR con tu celular para chatear por WhatsApp.', 'solutiontech-customer-chat' ), ), ) ); } /** * Generate dynamic CSS for button offsets and colors. * * @param array $settings Plugin settings. * @return string Inline CSS. */ private function generate_custom_css( $settings ) { $position = ( 'bottom-left' === $settings['position'] ) ? 'left' : 'right'; $offset_x = absint( $settings['offset_x'] ); $offset_y = absint( $settings['offset_y'] ); $primary = sanitize_hex_color( $settings['primary_color'] ); $header_col = sanitize_hex_color( $settings['header_color'] ); $css = " :root { --st-wa-primary: {$primary}; --st-wa-header: {$header_col}; } .st-wa-widget-wrapper { bottom: {$offset_y}px; {$position}: {$offset_x}px; } .st-wa-popup-wrapper { bottom: calc({$offset_y}px + 70px); {$position}: {$offset_x}px; } "; // Device visibility rules. if ( 'desktop' === $settings['device_visibility'] ) { $css .= "@media (max-width: 768px) { .st-wa-widget-wrapper, .st-wa-popup-wrapper { display: none !important; } }"; } elseif ( 'mobile' === $settings['device_visibility'] ) { $css .= "@media (min-width: 769px) { .st-wa-widget-wrapper, .st-wa-popup-wrapper { display: none !important; } }"; } return $css; } /** * Render floating button and chat popup in wp_footer. */ public function render_widget() { if ( ! $this->should_render() ) { return; } $settings = Solutiontech_WhatsApp_Helpers::get_settings(); $is_multi = ( '1' === $settings['multi_agent'] ); $is_popup = ( '1' === $settings['popup_enabled'] ); $is_online = Solutiontech_WhatsApp_Helpers::is_within_business_hours( $settings ); $layout_type = $settings['layout_type']; $animation_class = ( 'none' !== $settings['animation'] ) ? 'st-wa-anim-' . esc_attr( $settings['animation'] ) : ''; $default_message = Solutiontech_WhatsApp_Helpers::replace_tags( $settings['default_message'] ); $direct_url = Solutiontech_WhatsApp_Helpers::build_whatsapp_url( $settings['phone_number'], $default_message ); $status_text = $is_online ? $settings['agent_role'] : ( ! empty( $settings['offline_status_text'] ) ? $settings['offline_status_text'] : __( 'Fuera de línea', 'solutiontech-customer-chat' ) ); $dot_class = $is_online ? 'st-wa-status-online' : 'st-wa-status-offline'; ?>
1