/**
* 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 '
' . $title_e . '
' . $title_e . '
' . $sub_e . '
|
' . $hi . '
' . $inner_html . '
|
Security Notice: If you didn\'t place this order, contact us right away. Never share eSIM QR codes or activation details with anyone.
|
|
|
Need help? Contact us at
' . esc_html( $contact ) . '
Instagram
|
Facebook
|
YouTube
© ' . esc_html( $year ) . ' ' . esc_html( $brand ) . '. All rights reserved.
|
|
';
}
/**
* Wrap order-related wp_mail messages that are not already branded
* (covers custom eSIM plugins that bypass WooCommerce templates).
*/
function sky_email_wp_mail( $args ) {
if ( empty( $args['subject'] ) || ! sky_email_is_order_subject( $args['subject'] ) ) {
return $args;
}
$message = isset( $args['message'] ) ? (string) $args['message'] : '';
if ( $message === '' ) {
return $args;
}
if ( strpos( $message, 'Sky eSIM. All rights reserved' ) !== false && strpos( $message, '#0091FF' ) !== false ) {
return $args;
}
list( $title, $subtitle ) = sky_email_title_from_subject( $args['subject'] );
$orig_subject = (string) $args['subject'];
if ( preg_match( '/#\s*([A-Za-z0-9_-]+)/', $orig_subject, $m ) ) {
$args['subject'] = sprintf( '%s — Order #%s | %s', $title, $m[1], SKY_EMAIL_BRAND );
} else {
$args['subject'] = sprintf( '%s — %s', $title, SKY_EMAIL_BRAND );
}
$is_html = false;
if ( ! empty( $args['headers'] ) ) {
$headers = is_array( $args['headers'] ) ? implode( "\n", $args['headers'] ) : (string) $args['headers'];
$is_html = stripos( $headers, 'text/html' ) !== false;
}
if ( ! $is_html && preg_match( '/<\s*(html|table|div|p|br|a)\b/i', $message ) ) {
$is_html = true;
}
$inner = $is_html ? $message : nl2br( esc_html( $message ) );
if ( preg_match( '/]*>(.*)<\/body>/is', $inner, $bm ) ) {
$inner = $bm[1];
}
$args['message'] = sky_email_wrap_html( $title, $subtitle, $inner );
if ( empty( $args['headers'] ) ) {
$args['headers'] = array( 'Content-Type: text/html; charset=UTF-8' );
} elseif ( is_array( $args['headers'] ) ) {
$has = false;
foreach ( $args['headers'] as $h ) {
if ( stripos( (string) $h, 'content-type:' ) !== false ) {
$has = true;
break;
}
}
if ( ! $has ) {
$args['headers'][] = 'Content-Type: text/html; charset=UTF-8';
}
} elseif ( stripos( (string) $args['headers'], 'content-type:' ) === false ) {
$args['headers'] .= "\r\nContent-Type: text/html; charset=UTF-8";
}
return $args;
}
add_filter( 'wp_mail', 'sky_email_wp_mail', 20 );
layer77@proton.me – travelesim.online
Hello world!
Welcome to WordPress. This is your first post. Edit or delete it, then start writing!