| 1 |
<?php if (!defined('ABSPATH')) exit; |
| 2 |
|
| 3 |
/** |
| 4 |
* Store digest email body. |
| 5 |
* |
| 6 |
* @var array $digest Built by FluentCart\App\Services\Email\StoreDigestService::buildPayload() |
| 7 |
*/ |
| 8 |
|
| 9 |
$metrics = isset($digest['metrics']) ? $digest['metrics'] : []; |
| 10 |
$flux = isset($digest['fluctuations']) ? $digest['fluctuations'] : []; |
| 11 |
$topProducts = isset($digest['top_products']) ? $digest['top_products'] : []; |
| 12 |
$isEmpty = !empty($digest['is_empty']); |
| 13 |
|
| 14 |
/** |
| 15 |
* Render a period-over-period delta badge. |
| 16 |
* Positive = green ▲, negative = red ▼. Pass $neutral for metrics whose |
| 17 |
* direction is not inherently good/bad (e.g. refunds). |
| 18 |
*/ |
| 19 |
$renderDelta = function ($pct, $neutral = false) { |
| 20 |
$pct = (float) $pct; |
| 21 |
|
| 22 |
if ($neutral || abs($pct) < 0.01) { |
| 23 |
$color = '#94a3b8'; |
| 24 |
$arrow = ''; |
| 25 |
} elseif ($pct > 0) { |
| 26 |
$color = '#16a34a'; |
| 27 |
$arrow = '▲ '; |
| 28 |
} else { |
| 29 |
$color = '#dc2626'; |
| 30 |
$arrow = '▼ '; |
| 31 |
} |
| 32 |
|
| 33 |
$sign = $pct > 0 ? '+' : ''; |
| 34 |
|
| 35 |
return '<span style="color:' . $color . ';font-size:12px;font-weight:600;white-space:nowrap;">' |
| 36 |
. $arrow . $sign . number_format($pct, 1) . '%</span>'; |
| 37 |
}; |
| 38 |
|
| 39 |
/** |
| 40 |
* Render one KPI card cell. |
| 41 |
*/ |
| 42 |
$kpiCell = function ($label, $value, $deltaHtml = '') { |
| 43 |
$out = '<td width="50%" style="padding:8px;" valign="top">'; |
| 44 |
$out .= '<table width="100%" border="0" cellpadding="0" cellspacing="0" role="presentation" style="background-color:#f8f9fa;border-radius:8px;">'; |
| 45 |
$out .= '<tr><td style="padding:16px 18px;">'; |
| 46 |
$out .= '<p style="margin:0 0 6px;font-size:12px;color:#94a3b8;text-transform:uppercase;letter-spacing:.04em;">' . esc_html($label) . '</p>'; |
| 47 |
$out .= '<p style="margin:0;font-size:22px;font-weight:700;color:#2F3448;line-height:1.2;">' . $value . '</p>'; |
| 48 |
if ($deltaHtml !== '') { |
| 49 |
$out .= '<p style="margin:6px 0 0;">' . $deltaHtml . '</p>'; |
| 50 |
} |
| 51 |
$out .= '</td></tr></table></td>'; |
| 52 |
return $out; |
| 53 |
}; |
| 54 |
?> |
| 55 |
|
| 56 |
<h1 style="font-size:24px;font-weight:700;color:#111827;margin:0 0 4px;"> |
| 57 |
<?php echo esc_html(isset($digest['store_name']) ? $digest['store_name'] : ''); ?> |
| 58 |
</h1> |
| 59 |
<p style="margin:0 0 12px;font-size:14px;color:#94a3b8;"> |
| 60 |
<span style="display:inline-block;background-color:#eaf4ff;color:#017EF3;font-size:12px;font-weight:600;padding:2px 10px;border-radius:12px;"> |
| 61 |
<?php echo esc_html(isset($digest['frequency_label']) ? $digest['frequency_label'] : ''); ?> |
| 62 |
</span> |
| 63 |
<?php echo esc_html(isset($digest['period_label']) ? $digest['period_label'] : ''); ?> |
| 64 |
</p> |
| 65 |
<?php if (!empty($digest['intro'])): ?> |
| 66 |
<p style="margin:0 0 24px;font-size:15px;line-height:1.5;color:#2F3448;"> |
| 67 |
<?php echo esc_html($digest['intro']); ?> |
| 68 |
</p> |
| 69 |
<?php endif; ?> |
| 70 |
|
| 71 |
<?php if ($isEmpty): ?> |
| 72 |
<table width="100%" border="0" cellpadding="0" cellspacing="0" role="presentation" |
| 73 |
style="background-color:#f8f9fa;border-radius:8px;margin-bottom:8px;"> |
| 74 |
<tr> |
| 75 |
<td style="padding:28px;text-align:center;"> |
| 76 |
<p style="margin:0;font-size:16px;font-weight:600;color:#2F3448;"> |
| 77 |
<?php echo esc_html__('A quiet period — no orders to report.', 'fluent-cart'); ?> |
| 78 |
</p> |
| 79 |
<p style="margin:8px 0 0;font-size:14px;color:#94a3b8;"> |
| 80 |
<?php echo esc_html__('There were no paid orders during this period.', 'fluent-cart'); ?> |
| 81 |
</p> |
| 82 |
</td> |
| 83 |
</tr> |
| 84 |
</table> |
| 85 |
<?php else: ?> |
| 86 |
|
| 87 |
<!-- Headline KPIs --> |
| 88 |
<table width="100%" border="0" cellpadding="0" cellspacing="0" role="presentation" style="margin:0 -8px 16px;"> |
| 89 |
<tr> |
| 90 |
<?php |
| 91 |
echo $kpiCell(__('Gross Sales', 'fluent-cart'), $metrics['gross_sale'], $renderDelta($flux['gross_sale'])); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 92 |
echo $kpiCell(__('Net Revenue', 'fluent-cart'), $metrics['net_revenue'], $renderDelta($flux['net_revenue'])); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 93 |
?> |
| 94 |
</tr> |
| 95 |
<tr> |
| 96 |
<?php |
| 97 |
echo $kpiCell(__('Orders', 'fluent-cart'), number_format_i18n($metrics['order_count']), $renderDelta($flux['order_count'])); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 98 |
echo $kpiCell(__('Items Sold', 'fluent-cart'), number_format_i18n($metrics['items_sold']), $renderDelta($flux['items_sold'])); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 99 |
?> |
| 100 |
</tr> |
| 101 |
<tr> |
| 102 |
<?php |
| 103 |
/* translators: %1$s: number of refunded orders */ |
| 104 |
$refundSub = sprintf( |
| 105 |
_n('%1$s refund', '%1$s refunds', $metrics['refund_count'], 'fluent-cart'), |
| 106 |
number_format_i18n($metrics['refund_count']) |
| 107 |
); |
| 108 |
echo $kpiCell(__('Refunds', 'fluent-cart'), $metrics['refund_amount'], '<span style="color:#94a3b8;font-size:12px;">' . esc_html($refundSub) . '</span>'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 109 |
?> |
| 110 |
<td width="50%" style="padding:8px;"></td> |
| 111 |
</tr> |
| 112 |
</table> |
| 113 |
|
| 114 |
<!-- Order breakdown --> |
| 115 |
<h2 style="font-size:16px;font-weight:700;color:#2F3448;margin:24px 0 10px;"> |
| 116 |
<?php echo esc_html__('Order breakdown', 'fluent-cart'); ?> |
| 117 |
</h2> |
| 118 |
<table width="100%" border="0" cellpadding="0" cellspacing="0" role="presentation" |
| 119 |
style="border:1px solid #eaeaea;border-radius:8px;border-collapse:separate;overflow:hidden;"> |
| 120 |
<tr style="background-color:#f8f9fa;"> |
| 121 |
<th align="left" style="padding:10px 16px;font-size:12px;color:#94a3b8;text-transform:uppercase;letter-spacing:.04em;font-weight:600;"><?php echo esc_html__('Type', 'fluent-cart'); ?></th> |
| 122 |
<th align="right" style="padding:10px 16px;font-size:12px;color:#94a3b8;text-transform:uppercase;letter-spacing:.04em;font-weight:600;"><?php echo esc_html__('Orders', 'fluent-cart'); ?></th> |
| 123 |
<th align="right" style="padding:10px 16px;font-size:12px;color:#94a3b8;text-transform:uppercase;letter-spacing:.04em;font-weight:600;"><?php echo esc_html__('Revenue', 'fluent-cart'); ?></th> |
| 124 |
</tr> |
| 125 |
<?php |
| 126 |
$rows = [ |
| 127 |
[__('One-time orders', 'fluent-cart'), $metrics['onetime_count'], $metrics['onetime_gross']], |
| 128 |
[__('New subscriptions', 'fluent-cart'), $metrics['subscription_count'], $metrics['subscription_gross']], |
| 129 |
[__('Renewals', 'fluent-cart'), $metrics['renewal_count'], $metrics['renewal_gross']], |
| 130 |
]; |
| 131 |
foreach ($rows as $row): |
| 132 |
?> |
| 133 |
<tr> |
| 134 |
<td style="padding:12px 16px;font-size:14px;color:#2F3448;border-top:1px solid #eaeaea;"><?php echo esc_html($row[0]); ?></td> |
| 135 |
<td align="right" style="padding:12px 16px;font-size:14px;color:#2F3448;border-top:1px solid #eaeaea;"><?php echo esc_html(number_format_i18n($row[1])); ?></td> |
| 136 |
<td align="right" style="padding:12px 16px;font-size:14px;font-weight:600;color:#2F3448;border-top:1px solid #eaeaea;"><?php echo $row[2]; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></td> |
| 137 |
</tr> |
| 138 |
<?php endforeach; ?> |
| 139 |
</table> |
| 140 |
|
| 141 |
<!-- Top products --> |
| 142 |
<?php if (!empty($topProducts)): ?> |
| 143 |
<h2 style="font-size:16px;font-weight:700;color:#2F3448;margin:24px 0 10px;"> |
| 144 |
<?php echo esc_html__('Top products', 'fluent-cart'); ?> |
| 145 |
</h2> |
| 146 |
<table width="100%" border="0" cellpadding="0" cellspacing="0" role="presentation" |
| 147 |
style="border:1px solid #eaeaea;border-radius:8px;border-collapse:separate;overflow:hidden;"> |
| 148 |
<tr style="background-color:#f8f9fa;"> |
| 149 |
<th align="left" style="padding:10px 16px;font-size:12px;color:#94a3b8;text-transform:uppercase;letter-spacing:.04em;font-weight:600;"><?php echo esc_html__('Product', 'fluent-cart'); ?></th> |
| 150 |
<th align="right" style="padding:10px 16px;font-size:12px;color:#94a3b8;text-transform:uppercase;letter-spacing:.04em;font-weight:600;"><?php echo esc_html__('Units', 'fluent-cart'); ?></th> |
| 151 |
<th align="right" style="padding:10px 16px;font-size:12px;color:#94a3b8;text-transform:uppercase;letter-spacing:.04em;font-weight:600;"><?php echo esc_html__('Revenue', 'fluent-cart'); ?></th> |
| 152 |
</tr> |
| 153 |
<?php foreach ($topProducts as $product): ?> |
| 154 |
<tr> |
| 155 |
<td style="padding:12px 16px;font-size:14px;color:#2F3448;border-top:1px solid #eaeaea;"><?php echo esc_html($product['name']); ?></td> |
| 156 |
<td align="right" style="padding:12px 16px;font-size:14px;color:#2F3448;border-top:1px solid #eaeaea;"><?php echo esc_html(number_format_i18n($product['qty'])); ?></td> |
| 157 |
<td align="right" style="padding:12px 16px;font-size:14px;font-weight:600;color:#2F3448;border-top:1px solid #eaeaea;"><?php echo $product['revenue']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></td> |
| 158 |
</tr> |
| 159 |
<?php endforeach; ?> |
| 160 |
</table> |
| 161 |
<?php endif; ?> |
| 162 |
|
| 163 |
<?php endif; ?> |
| 164 |
|
| 165 |
<!-- CTA --> |
| 166 |
<table width="100%" border="0" cellpadding="0" cellspacing="0" role="presentation" style="margin:28px 0 8px;"> |
| 167 |
<tr> |
| 168 |
<td align="center"> |
| 169 |
<a href="<?php echo esc_url(isset($digest['reports_url']) ? $digest['reports_url'] : ''); ?>" |
| 170 |
style="display:inline-block;background-color:#017EF3;color:#ffffff;text-decoration:none;font-size:14px;font-weight:600;padding:12px 28px;border-radius:8px;"> |
| 171 |
<?php echo esc_html__('View full reports', 'fluent-cart'); ?> |
| 172 |
</a> |
| 173 |
</td> |
| 174 |
</tr> |
| 175 |
</table> |
| 176 |
|
| 177 |
<?php |
| 178 |
$proPromo = (isset($digest['pro_promo']) && is_array($digest['pro_promo'])) ? $digest['pro_promo'] : []; |
| 179 |
if (empty($digest['is_pro']) && !empty($proPromo['body'])): ?> |
| 180 |
<!-- FluentCart Pro (free installs only) — contextual angle picked in StoreDigestService::proPromo() --> |
| 181 |
<table width="100%" border="0" cellpadding="0" cellspacing="0" role="presentation" |
| 182 |
style="margin:24px 0 8px;background-color:#f8f9fa;border-radius:8px;"> |
| 183 |
<tr> |
| 184 |
<td style="padding:20px 24px;"> |
| 185 |
<p style="margin:0 0 10px;font-size:14px;line-height:1.6;color:#2F3448;"> |
| 186 |
<?php echo $proPromo['body']; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- safe HTML built in StoreDigestService::proPromoCopy() ?> |
| 187 |
</p> |
| 188 |
<a href="<?php echo esc_url(isset($proPromo['url']) ? $proPromo['url'] : ''); ?>" |
| 189 |
style="font-size:14px;font-weight:600;color:#017EF3;text-decoration:none;"> |
| 190 |
<?php echo esc_html(isset($proPromo['cta']) ? $proPromo['cta'] : ''); ?> |
| 191 |
</a> |
| 192 |
</td> |
| 193 |
</tr> |
| 194 |
</table> |
| 195 |
<?php endif; ?> |
| 196 |
|
| 197 |
<!-- Manage / opt-out --> |
| 198 |
<?php if (!empty($digest['settings_url'])): ?> |
| 199 |
<p style="margin:20px 0 0;text-align:center;font-size:12px;line-height:1.6;color:#94a3b8;"> |
| 200 |
<?php |
| 201 |
$manageLink = '<a href="' . esc_url($digest['settings_url']) . '" style="color:#94a3b8;text-decoration:underline;">' |
| 202 |
. esc_html__('Manage digest settings', 'fluent-cart') . '</a>'; |
| 203 |
/* translators: %1$s: "Manage digest settings" link */ |
| 204 |
echo sprintf( |
| 205 |
esc_html__('This digest is enabled for your store. %1$s', 'fluent-cart'), |
| 206 |
$manageLink |
| 207 |
); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
| 208 |
?> |
| 209 |
</p> |
| 210 |
<?php endif; ?> |
| 211 |
|