'1', 'phone_number' => '', 'agent_name' => 'Equipo de Soporte', 'agent_role' => 'Suele responder en pocos minutos', 'default_message' => '¡Hola! Me gustaría recibir más información sobre {page_title}. Enlace: {page_url}', 'multi_agent' => '0', 'agents' => array(), // Popup. 'popup_enabled' => '1', 'popup_title' => 'Inicia una conversación', 'popup_intro' => '¡Hola! ¿Cómo podemos ayudarte hoy? Escríbenos directamente a WhatsApp.', 'btn_cta_text' => 'Chatear por WhatsApp', // Design. 'position' => 'bottom-right', 'offset_x' => '20', 'offset_y' => '20', 'layout_type' => 'button_text', 'btn_text' => '¿Necesitas ayuda?', 'primary_color' => '#25D366', 'header_color' => '#075E54', 'animation' => 'pulse', 'device_visibility' => 'all', 'hide_on_pages' => array(), // WooCommerce. 'woo_enabled' => '1', 'woo_btn_position' => 'woocommerce_after_add_to_cart_button', 'woo_btn_text' => 'Pedir por WhatsApp', 'woo_message' => '¡Hola! Me interesa comprar "{product_name}" (SKU: {product_sku}, Precio: {product_price}). Enlace: {product_url}', 'woo_cart_enabled' => '1', 'woo_cart_btn_text' => 'Hacer consulta sobre mi carrito', // Analytics. 'track_ga4' => '1', 'track_pixel' => '1', // Feature 1: Notification Badge. 'badge_enabled' => '1', 'badge_delay' => '3', // Feature 2: Smart Triggers. 'auto_open_delay' => '0', // 0 = disabled. 'scroll_trigger' => '0', 'scroll_percent' => '50', 'exit_intent' => '0', // Feature 3: Business Hours. 'business_hours_enabled' => '0', 'business_days' => array( 'mon', 'tue', 'wed', 'thu', 'fri' ), 'business_start' => '09:00', 'business_end' => '18:00', 'offline_behavior' => 'offline_notice', // offline_notice or hide_widget. 'offline_status_text' => 'Fuera de horario laboral', 'offline_notice' => 'En este momento estamos fuera de horario comercial. Envíanos tu consulta y te responderemos a primera hora.', // Feature 4: Desktop QR Code. 'qr_enabled' => '1', // Feature 5: Privacy / GDPR. 'gdpr_enabled' => '0', 'gdpr_text' => 'Acepto la política de privacidad y el contacto vía WhatsApp.', // Feature 6: Notification Sound. 'sound_enabled' => '1', ); $saved = get_option( 'st_wa_settings', array() ); return wp_parse_args( $saved, $defaults ); } /** * Sanitize phone number to international numeric format (digits only). * * @param string $phone Raw phone string. * @return string Digits only. */ public static function clean_phone( $phone ) { return preg_replace( '/[^0-9]/', '', (string) $phone ); } /** * Build WhatsApp link. * * @param string $phone Clean phone digits. * @param string $message Plain text message. * @return string WhatsApp URL. */ public static function build_whatsapp_url( $phone, $message = '' ) { $clean_phone = self::clean_phone( $phone ); $url = 'https://wa.me/' . $clean_phone; if ( ! empty( $message ) ) { $url = add_query_arg( 'text', rawurlencode( $message ), $url ); } return esc_url_raw( $url ); } /** * Replace dynamic placeholders in messages. * * @param string $message Message template. * @param array $custom_tags Additional key => value replacements. * @return string Processed text. */ public static function replace_tags( $message, $custom_tags = array() ) { $page_title = wp_title( '', false ); if ( is_front_page() || is_home() ) { $page_title = get_bloginfo( 'name' ); } elseif ( empty( $page_title ) && is_singular() ) { $page_title = get_the_title(); } $current_url = home_url( add_query_arg( array(), $GLOBALS['wp']->request ?? '' ) ); $defaults = array( '{site_name}' => get_bloginfo( 'name' ), '{page_title}' => trim( $page_title ), '{page_url}' => esc_url( $current_url ), ); $tags = array_merge( $defaults, $custom_tags ); return str_replace( array_keys( $tags ), array_values( $tags ), $message ); } /** * Check whether the current time is within configured business hours. * * @param array $settings Plugin settings. * @return bool True if online, false if offline. */ public static function is_within_business_hours( $settings ) { if ( empty( $settings['business_hours_enabled'] ) || '1' !== $settings['business_hours_enabled'] ) { return true; } $timezone = wp_timezone(); $now = new DateTime( 'now', $timezone ); $current_day = strtolower( $now->format( 'D' ) ); // mon, tue, wed, thu, fri, sat, sun. $active_days = ! empty( $settings['business_days'] ) && is_array( $settings['business_days'] ) ? $settings['business_days'] : array( 'mon', 'tue', 'wed', 'thu', 'fri' ); if ( ! in_array( $current_day, $active_days, true ) ) { return false; } $start = ! empty( $settings['business_start'] ) ? $settings['business_start'] : '09:00'; $end = ! empty( $settings['business_end'] ) ? $settings['business_end'] : '18:00'; $current_time = $now->format( 'H:i' ); return ( $current_time >= $start && $current_time <= $end ); } /** * Get the SVG code for WhatsApp icon. * * @return string Raw SVG. */ public static function get_whatsapp_icon_svg() { return ''; } }