/** * Sky eSIM branded transactional emails (loaded from the child theme). */ defined( 'ABSPATH' ) || exit; if ( defined( 'SKY_EMAIL_BRANDING_LOADED' ) ) { return; } define( 'SKY_EMAIL_BRANDING_LOADED', true ); define( 'SKY_EMAIL_BRAND', 'Sky eSIM' ); define( 'SKY_EMAIL_BLUE', '#0091FF' ); define( 'SKY_EMAIL_CONTACT', 'contact@skyesim.app' ); if ( ! defined( 'SKY_EMAIL_PLUGIN_DIR' ) ) { if ( function_exists( 'plugin_dir_path' ) && strpos( __FILE__, 'plugins' ) !== false ) { define( 'SKY_EMAIL_PLUGIN_DIR', dirname( __DIR__ ) . '/' ); } else { define( 'SKY_EMAIL_PLUGIN_DIR', trailingslashit( get_stylesheet_directory() ) . 'woocommerce/' ); } } /** * Locate overridden WooCommerce email templates in this plugin. */ function sky_email_locate_template( $template, $template_name, $template_path ) { if ( strpos( $template_name, 'emails/' ) !== 0 ) { return $template; } $custom = SKY_EMAIL_PLUGIN_DIR . 'templates/' . $template_name; if ( ! is_readable( $custom ) ) { $custom = SKY_EMAIL_PLUGIN_DIR . $template_name; } if ( is_readable( $custom ) ) { return $custom; } return $template; } add_filter( 'woocommerce_locate_template', 'sky_email_locate_template', 20, 3 ); /** * WooCommerce email CSS — match branded card layout. */ function sky_email_styles( $css ) { $blue = SKY_EMAIL_BLUE; $extra = " body { background-color: #f3f4f6 !important; font-family: Arial, Helvetica, sans-serif !important; } #wrapper { background-color: #f3f4f6 !important; padding: 24px 12px !important; } #template_container { background-color: #ffffff !important; border: none !important; border-radius: 12px !important; box-shadow: 0 1px 3px rgba(0,0,0,0.06) !important; } #template_header { background-color: {$blue} !important; border-radius: 0 !important; color: #ffffff !important; border: none !important; } #template_header h1 { color: #ffffff !important; font-size: 28px !important; font-weight: 700 !important; } #body_content { background-color: #ffffff !important; } #body_content_inner { color: #1f2937 !important; font-family: Arial, Helvetica, sans-serif !important; font-size: 15px !important; line-height: 1.6 !important; } .td { color: #1f2937 !important; border-color: #e5e7eb !important; } .address, address { border: 1px solid #e5e7eb !important; border-radius: 8px !important; } a { color: {$blue} !important; } .button, a.button { background-color: {$blue} !important; border-color: {$blue} !important; color: #ffffff !important; border-radius: 8px !important; } #template_footer { background: #ffffff !important; } #template_footer #credit { color: #9ca3af !important; font-size: 12px !important; } "; return $css . $extra; } add_filter( 'woocommerce_email_styles', 'sky_email_styles', 20 ); function sky_email_order_number( $order ) { if ( is_object( $order ) && method_exists( $order, 'get_order_number' ) ) { return (string) $order->get_order_number(); } return ''; } function sky_email_subject_processing( $subject, $order ) { $num = sky_email_order_number( $order ); return $num ? sprintf( 'Order Processing — Order #%s | %s', $num, SKY_EMAIL_BRAND ) : 'Order Processing — ' . SKY_EMAIL_BRAND; } add_filter( 'woocommerce_email_subject_customer_processing_order', 'sky_email_subject_processing', 20, 2 ); function sky_email_subject_completed( $subject, $order ) { $num = sky_email_order_number( $order ); return $num ? sprintf( 'Order Delivered — Order #%s | %s', $num, SKY_EMAIL_BRAND ) : 'Order Delivered — ' . SKY_EMAIL_BRAND; } add_filter( 'woocommerce_email_subject_customer_completed_order', 'sky_email_subject_completed', 20, 2 ); function sky_email_subject_on_hold( $subject, $order ) { $num = sky_email_order_number( $order ); return $num ? sprintf( 'Order Confirmation — Order #%s | %s', $num, SKY_EMAIL_BRAND ) : 'Order Confirmation — ' . SKY_EMAIL_BRAND; } add_filter( 'woocommerce_email_subject_customer_on_hold_order', 'sky_email_subject_on_hold', 20, 2 ); function sky_email_subject_invoice( $subject, $order ) { $num = sky_email_order_number( $order ); return $num ? sprintf( 'Order Confirmation — Order #%s | %s', $num, SKY_EMAIL_BRAND ) : 'Order Confirmation — ' . SKY_EMAIL_BRAND; } add_filter( 'woocommerce_email_subject_customer_invoice', 'sky_email_subject_invoice', 20, 2 ); add_filter( 'woocommerce_email_heading_customer_processing_order', function () { return 'Order Processing'; }, 20 ); add_filter( 'woocommerce_email_heading_customer_completed_order', function () { return 'Order Delivered'; }, 20 ); add_filter( 'woocommerce_email_heading_customer_on_hold_order', function () { return 'Order Confirmation'; }, 20 ); add_filter( 'woocommerce_email_heading_customer_invoice', function () { return 'Order Confirmation'; }, 20 ); /** * Subtitle under the blue header for WC emails. */ function sky_email_subtitle_for_heading( $heading ) { $h = strtolower( (string) $heading ); if ( strpos( $h, 'deliver' ) !== false || strpos( $h, 'complete' ) !== false ) { return 'Your eSIM is ready'; } if ( strpos( $h, 'process' ) !== false ) { return 'We\'re preparing your eSIM'; } if ( strpos( $h, 'confirm' ) !== false ) { return 'Thanks for your order'; } return 'Welcome to ' . SKY_EMAIL_BRAND . '!'; } function sky_email_is_order_subject( $subject ) { $s = strtolower( (string) $subject ); foreach ( array( 'order confirmation', 'order processing', 'order delivered', 'order #', 'your order', 'sky esim', 'sky e-sim', 'globe esim', 'qr code', 'activation code', 'esim delivery', ) as $n ) { if ( strpos( $s, $n ) !== false ) { return true; } } return false; } function sky_email_title_from_subject( $subject ) { $s = strtolower( (string) $subject ); if ( strpos( $s, 'deliver' ) !== false || strpos( $s, 'completed' ) !== false ) { return array( 'Order Delivered', 'Your eSIM is ready' ); } if ( strpos( $s, 'process' ) !== false ) { return array( 'Order Processing', 'We\'re preparing your eSIM' ); } if ( strpos( $s, 'confirm' ) !== false || strpos( $s, 'received' ) !== false || strpos( $s, 'invoice' ) !== false ) { return array( 'Order Confirmation', 'Thanks for your order' ); } return array( 'Sky eSIM Update', 'Thanks for choosing Sky eSIM' ); } /** * Build branded HTML shell around an inner body. */ function sky_email_wrap_html( $title, $subtitle, $inner_html, $greeting_name = '' ) { $blue = SKY_EMAIL_BLUE; $contact = SKY_EMAIL_CONTACT; $brand = SKY_EMAIL_BRAND; $year = gmdate( 'Y' ); $title_e = esc_html( $title ); $sub_e = esc_html( $subtitle ); $name = trim( (string) $greeting_name ); $hi = $name !== '' ? '
Hi ' . esc_html( $name ) . '!
' : ''; return '