+
+ );
+}
diff --git a/customer-spa/tailwind.config.js b/customer-spa/tailwind.config.js
index b9ec562..baf522f 100644
--- a/customer-spa/tailwind.config.js
+++ b/customer-spa/tailwind.config.js
@@ -25,5 +25,5 @@ module.exports = {
borderRadius: { lg: "12px", md: "10px", sm: "8px" }
}
},
- plugins: [require("tailwindcss-animate")]
+ plugins: [require("tailwindcss-animate"), require("@tailwindcss/typography")]
};
\ No newline at end of file
diff --git a/includes/Admin/AppearanceController.php b/includes/Admin/AppearanceController.php
index 5ca20d7..c774bf5 100644
--- a/includes/Admin/AppearanceController.php
+++ b/includes/Admin/AppearanceController.php
@@ -381,6 +381,7 @@ class AppearanceController
'image_position' => sanitize_text_field($data['layout']['image_position'] ?? 'left'),
'gallery_style' => sanitize_text_field($data['layout']['gallery_style'] ?? 'thumbnails'),
'sticky_add_to_cart' => (bool) ($data['layout']['sticky_add_to_cart'] ?? false),
+ 'layout_style' => sanitize_text_field($data['layout']['layout_style'] ?? 'flat'),
],
'elements' => [
'breadcrumbs' => (bool) ($data['elements']['breadcrumbs'] ?? true),
@@ -601,7 +602,11 @@ class AppearanceController
'show_icon' => true,
],
],
- 'product' => [],
+ 'product' => [
+ 'layout' => [
+ 'layout_style' => 'flat',
+ ],
+ ],
'cart' => [],
'checkout' => [],
'thankyou' => [],
diff --git a/includes/Admin/Assets.php b/includes/Admin/Assets.php
index 8c4201c..d09ed8b 100644
--- a/includes/Admin/Assets.php
+++ b/includes/Admin/Assets.php
@@ -75,7 +75,7 @@ class Assets
'pluginUrl' => trailingslashit(plugins_url('/', dirname(__DIR__))),
'storeUrl' => self::get_spa_url(),
'customerSpaEnabled' => get_option('woonoow_customer_spa_enabled', false),
- 'onboardingCompleted' => get_option('woonoow_onboarding_completed', false),
+ 'onboardingCompleted' => (get_option('woonoow_onboarding_completed', false) === 'yes' || get_option('woonoow_onboarding_completed') == 1),
]);
wp_add_inline_script($handle, 'window.WNW_CONFIG = window.WNW_CONFIG || WNW_CONFIG;', 'after');
@@ -201,7 +201,7 @@ class Assets
'pluginUrl' => trailingslashit(plugins_url('/', dirname(__DIR__))),
'storeUrl' => self::get_spa_url(),
'customerSpaEnabled' => get_option('woonoow_customer_spa_enabled', false),
- 'onboardingCompleted' => get_option('woonoow_onboarding_completed', false),
+ 'onboardingCompleted' => (get_option('woonoow_onboarding_completed', false) === 'yes' || get_option('woonoow_onboarding_completed') == 1),
]);
// WordPress REST API settings (for media upload compatibility)
diff --git a/includes/Admin/StandaloneAdmin.php b/includes/Admin/StandaloneAdmin.php
index 2457ac1..8055d1d 100644
--- a/includes/Admin/StandaloneAdmin.php
+++ b/includes/Admin/StandaloneAdmin.php
@@ -1,4 +1,5 @@
$user->ID,
'name' => $user->display_name,
'email' => $user->user_email,
- 'avatar' => get_avatar_url( $user->ID ),
+ 'avatar' => get_avatar_url($user->ID),
];
}
-
+
// Get WooCommerce store settings
$store_settings = self::get_store_settings();
-
+
// Get asset URLs
- $plugin_url = plugins_url( '', dirname( dirname( __FILE__ ) ) );
+ $plugin_url = plugins_url('', dirname(dirname(__FILE__)));
$asset_url = $plugin_url . '/admin-spa/dist';
-
+
// Cache busting
- $version = defined( 'WP_DEBUG' ) && WP_DEBUG ? time() : '1.0.0';
+ $version = defined('WP_DEBUG') && WP_DEBUG ? time() : '1.0.0';
$css_url = $asset_url . '/app.css?ver=' . $version;
$js_url = $asset_url . '/app.js?ver=' . $version;
-
+
// Render HTML
- ?>
-
-
-
-
-
-
-
Admin
-
-
-
-
-
+
+
+
+
+
+
+
+
Admin
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $currency,
'currency_symbol' => $currency_sym,
@@ -200,17 +210,17 @@ class StandaloneAdmin {
/** Get the SPA page URL from appearance settings (dynamic slug) */
private static function get_spa_url(): string
{
- $appearance_settings = get_option( 'woonoow_appearance_settings', [] );
+ $appearance_settings = get_option('woonoow_appearance_settings', []);
$spa_page_id = $appearance_settings['general']['spa_page'] ?? 0;
-
- if ( $spa_page_id ) {
- $spa_url = get_permalink( $spa_page_id );
- if ( $spa_url ) {
- return trailingslashit( $spa_url );
+
+ if ($spa_page_id) {
+ $spa_url = get_permalink($spa_page_id);
+ if ($spa_url) {
+ return trailingslashit($spa_url);
}
}
-
+
// Fallback to /store/ if no SPA page configured
- return home_url( '/store/' );
+ return home_url('/store/');
}
}
diff --git a/includes/Api/OnboardingController.php b/includes/Api/OnboardingController.php
index 09328fc..dfdf5e2 100644
--- a/includes/Api/OnboardingController.php
+++ b/includes/Api/OnboardingController.php
@@ -122,7 +122,7 @@ class OnboardingController extends WP_REST_Controller
}
// 4. Mark as Complete
- update_option('woonoow_onboarding_completed', true);
+ update_option('woonoow_onboarding_completed', 'yes');
return rest_ensure_response([
'success' => true,
diff --git a/includes/Api/PagesController.php b/includes/Api/PagesController.php
index 9a4ef63..a66b592 100644
--- a/includes/Api/PagesController.php
+++ b/includes/Api/PagesController.php
@@ -58,7 +58,7 @@ class PagesController
'permission_callback' => '__return_true',
]);
- // Get/Save CPT templates
+ // Get/Save/Delete CPT templates
register_rest_route($namespace, '/templates/(?P
[a-zA-Z0-9_-]+)', [
[
'methods' => 'GET',
@@ -70,6 +70,11 @@ class PagesController
'callback' => [__CLASS__, 'save_template'],
'permission_callback' => [__CLASS__, 'check_admin_permission'],
],
+ [
+ 'methods' => 'DELETE',
+ 'callback' => [__CLASS__, 'delete_template'],
+ 'permission_callback' => [__CLASS__, 'check_admin_permission'],
+ ],
]);
// Get post with template applied (for SPA rendering)
@@ -337,6 +342,34 @@ class PagesController
], 200);
}
+ /**
+ * Delete CPT template (abort SPA handling for this post type)
+ */
+ public static function delete_template(WP_REST_Request $request)
+ {
+ $cpt = $request->get_param('cpt');
+
+ // Validate CPT exists
+ if (!post_type_exists($cpt) && $cpt !== 'post') {
+ return new WP_Error('invalid_cpt', 'Invalid post type', ['status' => 400]);
+ }
+
+ $option_key = "wn_template_{$cpt}";
+ $exists = get_option($option_key, null);
+
+ if ($exists === null) {
+ return new WP_Error('not_found', 'No template found for this post type', ['status' => 404]);
+ }
+
+ delete_option($option_key);
+
+ return new WP_REST_Response([
+ 'success' => true,
+ 'cpt' => $cpt,
+ 'message' => 'Template deleted. WordPress will now handle this post type natively.',
+ ], 200);
+ }
+
/**
* Get content with template applied (for SPA rendering)
*/
@@ -378,7 +411,37 @@ class PagesController
if ($template && !empty($template['sections'])) {
foreach ($template['sections'] as $section) {
$resolved_section = $section;
- $resolved_section['props'] = PageSSR::resolve_props($section['props'] ?? [], $post_data);
+
+ // Pre-resolve special dynamic sources that produce arrays before PageSSR::resolve_props
+ $props = $section['props'] ?? [];
+ foreach ($props as $key => $prop) {
+ if (is_array($prop) && ($prop['type'] ?? '') === 'dynamic' && ($prop['source'] ?? '') === 'related_posts') {
+ $props[$key] = [
+ 'type' => 'static',
+ 'value' => PlaceholderRenderer::get_related_posts($post->ID, 3, $type),
+ ];
+ }
+ }
+
+ $resolved_section['props'] = PageSSR::resolve_props($props, $post_data);
+
+ // Resolve dynamicBackground in styles
+ // If styles.dynamicBackground === 'post_featured_image', set styles.backgroundImage from post data
+ $styles = $resolved_section['styles'] ?? [];
+ if (!empty($styles['dynamicBackground']) && (empty($styles['backgroundType']) || $styles['backgroundType'] === 'image')) {
+ $dyn_source = $styles['dynamicBackground'];
+ if ($dyn_source === 'post_featured_image' || $dyn_source === 'featured_image') {
+ $featured_url = $post_data['featured_image'] ?? '';
+ if (!empty($featured_url)) {
+ $styles['backgroundImage'] = $featured_url;
+ $styles['backgroundType'] = 'image';
+ }
+ }
+ // Remove the internal marker from the rendered output
+ unset($styles['dynamicBackground']);
+ $resolved_section['styles'] = $styles;
+ }
+
$rendered_sections[] = $resolved_section;
}
}
diff --git a/includes/Api/ProductsController.php b/includes/Api/ProductsController.php
index 996659c..07ea74b 100644
--- a/includes/Api/ProductsController.php
+++ b/includes/Api/ProductsController.php
@@ -46,6 +46,18 @@ class ProductsController
return trim($sanitized);
}
+ /**
+ * Sanitize rich text (allows HTML tags)
+ */
+ private static function sanitize_rich_text($value)
+ {
+ if (!isset($value) || $value === '') {
+ return '';
+ }
+ $sanitized = wp_kses_post($value);
+ return trim($sanitized);
+ }
+
/**
* Sanitize numeric value
*/
@@ -335,8 +347,12 @@ class ProductsController
$product->set_slug(self::sanitize_slug($data['slug']));
}
$product->set_status(sanitize_key($data['status'] ?? 'publish'));
- $product->set_description(self::sanitize_textarea($data['description'] ?? ''));
- $product->set_short_description(self::sanitize_textarea($data['short_description'] ?? ''));
+ if (isset($data['description'])) {
+ $product->set_description(self::sanitize_rich_text($data['description'] ?? ''));
+ }
+ if (isset($data['short_description'])) {
+ $product->set_short_description(self::sanitize_textarea($data['short_description'] ?? ''));
+ }
if (!empty($data['sku'])) {
$product->set_sku(self::sanitize_text($data['sku']));
@@ -489,7 +505,7 @@ class ProductsController
if (isset($data['name'])) $product->set_name(self::sanitize_text($data['name']));
if (isset($data['slug'])) $product->set_slug(self::sanitize_slug($data['slug']));
if (isset($data['status'])) $product->set_status(sanitize_key($data['status']));
- if (isset($data['description'])) $product->set_description(self::sanitize_textarea($data['description']));
+ if (isset($data['description'])) $product->set_description(self::sanitize_rich_text($data['description']));
if (isset($data['short_description'])) $product->set_short_description(self::sanitize_textarea($data['short_description']));
if (isset($data['sku'])) $product->set_sku(self::sanitize_text($data['sku']));
@@ -942,10 +958,17 @@ class ProductsController
$value = $term ? $term->name : $value;
}
} else {
- // Custom attribute - stored as lowercase in meta
- $meta_key = 'attribute_' . strtolower($attr_name);
+ // Custom attribute - stored as sanitize_title in meta
+ $sanitized_name = sanitize_title($attr_name);
+ $meta_key = 'attribute_' . $sanitized_name;
$value = get_post_meta($variation_id, $meta_key, true);
+ // Fallback to legacy lowercase if not found
+ if ($value === '') {
+ $meta_key_legacy = 'attribute_' . strtolower($attr_name);
+ $value = get_post_meta($variation_id, $meta_key_legacy, true);
+ }
+
// Capitalize the attribute name for display to match admin SPA
$clean_name = ucfirst($attr_name);
}
@@ -1029,8 +1052,27 @@ class ProductsController
foreach ($parent_attributes as $attr_name => $parent_attr) {
if (!$parent_attr->get_variation()) continue;
- if (strcasecmp($display_name, $attr_name) === 0 || strcasecmp($display_name, ucfirst($attr_name)) === 0) {
- $wc_attributes[strtolower($attr_name)] = strtolower($value);
+
+ $is_match = false;
+ if (strpos($attr_name, 'pa_') === 0) {
+ $label = wc_attribute_label($attr_name);
+ if (strcasecmp($display_name, $label) === 0 || strcasecmp($display_name, $attr_name) === 0) {
+ $is_match = true;
+ }
+ } else {
+ // Custom attribute: Check exact name, or sanitized version
+ if (
+ strcasecmp($display_name, $attr_name) === 0 ||
+ strcasecmp($display_name, $parent_attr->get_name()) === 0 ||
+ sanitize_title($display_name) === sanitize_title($attr_name)
+ ) {
+ $is_match = true;
+ }
+ }
+
+ if ($is_match) {
+ // WooCommerce expects the exact attribute slug as the key
+ $wc_attributes[$attr_name] = $value;
break;
}
}
@@ -1095,7 +1137,7 @@ class ProductsController
global $wpdb;
foreach ($wc_attributes as $attr_name => $attr_value) {
- $meta_key = 'attribute_' . $attr_name;
+ $meta_key = 'attribute_' . sanitize_title($attr_name);
$wpdb->delete(
$wpdb->postmeta,
diff --git a/includes/Core/Notifications/EmailManager.php b/includes/Core/Notifications/EmailManager.php
index fda2cc2..bb40187 100644
--- a/includes/Core/Notifications/EmailManager.php
+++ b/includes/Core/Notifications/EmailManager.php
@@ -1,4 +1,5 @@
init_hooks();
}
-
+
/**
* Initialize hooks
*/
- private function init_hooks() {
+ private function init_hooks()
+ {
// Disable WooCommerce emails to prevent duplicates
add_action('woocommerce_email', [$this, 'disable_wc_emails'], 1);
-
+
// Hook into WooCommerce order status changes
add_action('woocommerce_order_status_pending_to_processing', [$this, 'send_order_processing_email'], 10, 2);
add_action('woocommerce_order_status_pending_to_completed', [$this, 'send_order_completed_email'], 10, 2);
@@ -50,47 +55,49 @@ class EmailManager {
add_action('woocommerce_order_status_cancelled', [$this, 'send_order_cancelled_email'], 10, 2);
add_action('woocommerce_order_status_refunded', [$this, 'send_order_refunded_email'], 10, 2);
add_action('woocommerce_order_fully_refunded', [$this, 'send_order_refunded_email'], 10, 2);
-
+
// New order notification for admin
add_action('woocommerce_new_order', [$this, 'send_new_order_admin_email'], 10, 1);
-
+
// Customer note
add_action('woocommerce_new_customer_note', [$this, 'send_customer_note_email'], 10, 1);
-
+
// New customer account
add_action('woocommerce_created_customer', [$this, 'send_new_customer_email'], 10, 3);
-
+
// Password reset - intercept WordPress default email and use our template
add_filter('retrieve_password_message', [$this, 'handle_password_reset_email'], 10, 4);
-
+
// Low stock / Out of stock
add_action('woocommerce_low_stock', [$this, 'send_low_stock_email'], 10, 1);
add_action('woocommerce_no_stock', [$this, 'send_out_of_stock_email'], 10, 1);
add_action('woocommerce_product_set_stock', [$this, 'check_stock_levels'], 10, 1);
}
-
+
/**
* Check if WooNooW notification system is enabled
*
* @return bool
*/
- public static function is_enabled() {
+ public static function is_enabled()
+ {
// Check global notification system mode
$system_mode = get_option('woonoow_notification_system_mode', 'woonoow');
return $system_mode === 'woonoow';
}
-
+
/**
* Disable WooCommerce default emails
*
* @param WC_Emails $email_class
*/
- public function disable_wc_emails($email_class) {
+ public function disable_wc_emails($email_class)
+ {
// Only disable WC emails if WooNooW system is enabled
if (!self::is_enabled()) {
return; // Keep WC emails if WooNooW system disabled
}
-
+
// Disable all WooCommerce transactional emails
$emails_to_disable = [
'WC_Email_New_Order', // Admin: New order
@@ -105,181 +112,188 @@ class EmailManager {
'WC_Email_Customer_Reset_Password', // Customer: Reset password
'WC_Email_Customer_New_Account', // Customer: New account
];
-
+
foreach ($emails_to_disable as $email_id) {
add_filter('woocommerce_email_enabled_' . strtolower(str_replace('WC_Email_', '', $email_id)), '__return_false');
}
}
-
+
/**
* Send order processing email
*
* @param int $order_id
* @param WC_Order $order
*/
- public function send_order_processing_email($order_id, $order = null) {
+ public function send_order_processing_email($order_id, $order = null)
+ {
if (defined('WP_DEBUG') && WP_DEBUG) {
}
-
+
if (!$order) {
$order = wc_get_order($order_id);
}
-
+
if (!$order) {
if (defined('WP_DEBUG') && WP_DEBUG) {
}
return;
}
-
+
// Check if event is enabled
if (!$this->is_event_enabled('order_processing', 'email', 'customer')) {
if (defined('WP_DEBUG') && WP_DEBUG) {
}
return;
}
-
+
if (defined('WP_DEBUG') && WP_DEBUG) {
}
-
+
// Send email
$this->send_email('order_processing', 'customer', $order);
}
-
+
/**
* Send order completed email
*
* @param int $order_id
* @param WC_Order $order
*/
- public function send_order_completed_email($order_id, $order = null) {
+ public function send_order_completed_email($order_id, $order = null)
+ {
if (!$order) {
$order = wc_get_order($order_id);
}
-
+
if (!$order) {
return;
}
-
+
// Check if event is enabled
if (!$this->is_event_enabled('order_completed', 'email', 'customer')) {
return;
}
-
+
// Send email
$this->send_email('order_completed', 'customer', $order);
}
-
+
/**
* Send order on-hold email
*
* @param int $order_id
* @param WC_Order $order
*/
- public function send_order_on_hold_email($order_id, $order = null) {
+ public function send_order_on_hold_email($order_id, $order = null)
+ {
if (!$order) {
$order = wc_get_order($order_id);
}
-
+
if (!$order) {
return;
}
-
+
// Check if event is enabled
if (!$this->is_event_enabled('order_processing', 'email', 'customer')) {
return;
}
-
+
// Send email (use processing template for on-hold)
$this->send_email('order_processing', 'customer', $order);
}
-
+
/**
* Send order cancelled email
*
* @param int $order_id
* @param WC_Order $order
*/
- public function send_order_cancelled_email($order_id, $order = null) {
+ public function send_order_cancelled_email($order_id, $order = null)
+ {
if (!$order) {
$order = wc_get_order($order_id);
}
-
+
if (!$order) {
return;
}
-
+
// Send to admin
if ($this->is_event_enabled('order_cancelled', 'email', 'staff')) {
$this->send_email('order_cancelled', 'staff', $order);
}
}
-
+
/**
* Send order refunded email
*
* @param int $order_id
* @param WC_Order $order
*/
- public function send_order_refunded_email($order_id, $order = null) {
+ public function send_order_refunded_email($order_id, $order = null)
+ {
if (!$order) {
$order = wc_get_order($order_id);
}
-
+
if (!$order) {
return;
}
-
+
// Check if event is enabled
if (!$this->is_event_enabled('order_refunded', 'email', 'customer')) {
return;
}
-
+
// Send email
$this->send_email('order_refunded', 'customer', $order);
}
-
+
/**
* Send new order admin email
*
* @param int $order_id
*/
- public function send_new_order_admin_email($order_id) {
+ public function send_new_order_admin_email($order_id)
+ {
$order = wc_get_order($order_id);
-
+
if (!$order) {
return;
}
-
+
// Check if event is enabled
if (!$this->is_event_enabled('order_placed', 'email', 'staff')) {
return;
}
-
+
// Send email
$this->send_email('order_placed', 'staff', $order);
}
-
+
/**
* Send customer note email
*
* @param array $args
*/
- public function send_customer_note_email($args) {
+ public function send_customer_note_email($args)
+ {
$order = wc_get_order($args['order_id']);
-
+
if (!$order) {
return;
}
-
+
// Check if event is enabled
if (!$this->is_event_enabled('customer_note', 'email', 'customer')) {
return;
}
-
- // Send email with note data
- $this->send_email('customer_note', 'customer', $order, ['note' => $args['customer_note']]);
+
+ // Send email with note data — key must match {customer_note} variable in template
+ $this->send_email('customer_note', 'customer', $order, ['customer_note' => $args['customer_note']]);
}
-
+
/**
* Send new customer email
*
@@ -287,14 +301,15 @@ class EmailManager {
* @param array $new_customer_data
* @param bool $password_generated
*/
- public function send_new_customer_email($customer_id, $new_customer_data = [], $password_generated = false) {
+ public function send_new_customer_email($customer_id, $new_customer_data = [], $password_generated = false)
+ {
// Check if event is enabled
if (!$this->is_event_enabled('new_customer', 'email', 'customer')) {
return;
}
-
+
$customer = new \WC_Customer($customer_id);
-
+
// Send email
$this->send_email('new_customer', 'customer', $customer, [
'password_generated' => $password_generated,
@@ -302,7 +317,7 @@ class EmailManager {
'user_pass' => $new_customer_data['user_pass'] ?? '',
]);
}
-
+
/**
* Handle password reset email - intercept WordPress default and use our template
*
@@ -312,30 +327,31 @@ class EmailManager {
* @param WP_User $user_data User object
* @return string Empty string to prevent WordPress sending default email
*/
- public function handle_password_reset_email($message, $key, $user_login, $user_data) {
+ public function handle_password_reset_email($message, $key, $user_login, $user_data)
+ {
// Check if WooNooW notification system is enabled
if (!self::is_enabled()) {
return $message; // Use WordPress default
}
-
+
// Check if event is enabled
if (!$this->is_event_enabled('password_reset', 'email', 'customer')) {
return $message; // Use WordPress default
}
-
+
// Build reset URL - use SPA page from appearance settings
// The SPA page (e.g., /store/) loads customer-spa which has /reset-password route
$appearance_settings = get_option('woonoow_appearance_settings', []);
$spa_page_id = $appearance_settings['general']['spa_page'] ?? 0;
$use_browser_router = $appearance_settings['general']['use_browser_router'] ?? true;
-
+
if ($spa_page_id > 0) {
$spa_url = get_permalink($spa_page_id);
} else {
// Fallback to home URL if SPA page not configured
$spa_url = home_url('/');
}
-
+
// Build SPA reset password URL
// Use path format for BrowserRouter (SEO), hash format for HashRouter (legacy)
if ($use_browser_router) {
@@ -345,7 +361,7 @@ class EmailManager {
// Hash format: /store/#/reset-password?key=KEY&login=LOGIN
$reset_link = rtrim($spa_url, '/') . '#/reset-password?key=' . $key . '&login=' . rawurlencode($user_login);
}
-
+
// Create a pseudo WC_Customer for template rendering
$customer = null;
if (class_exists('WC_Customer')) {
@@ -355,14 +371,14 @@ class EmailManager {
$customer = null;
}
}
-
+
// Send our custom email
$this->send_password_reset_email($user_data, $key, $reset_link, $customer);
-
+
// Return empty string to prevent WordPress from sending its default plain-text email
return '';
}
-
+
/**
* Send password reset email using our template
*
@@ -371,10 +387,11 @@ class EmailManager {
* @param string $reset_link Full reset link URL
* @param WC_Customer|null $customer WooCommerce customer object if available
*/
- private function send_password_reset_email($user, $key, $reset_link, $customer = null) {
+ private function send_password_reset_email($user, $key, $reset_link, $customer = null)
+ {
// Get email renderer
$renderer = EmailRenderer::instance();
-
+
// Build extra data for template variables
$extra_data = [
'reset_key' => $key,
@@ -384,80 +401,86 @@ class EmailManager {
'customer_name' => $user->display_name ?: $user->user_login,
'customer_email' => $user->user_email,
];
-
+
// Use WC_Customer if available for better template rendering
$data = $customer ?: $user;
-
+
// Render email
$email = $renderer->render('password_reset', 'customer', $data, $extra_data);
-
+
if (!$email) {
if (defined('WP_DEBUG') && WP_DEBUG) {
}
return;
}
-
+
// Send email via wp_mail
$headers = [
'Content-Type: text/html; charset=UTF-8',
'From: ' . get_bloginfo('name') . ' <' . get_option('admin_email') . '>',
];
-
+
$sent = wp_mail($email['to'], $email['subject'], $email['body'], $headers);
-
+
if (defined('WP_DEBUG') && WP_DEBUG) {
}
-
+
// Log email sent
do_action('woonoow_email_sent', 'password_reset', 'customer', $email);
}
-
+
/**
* Send low stock email
*
* @param WC_Product $product
*/
- public function send_low_stock_email($product) {
+ public function send_low_stock_email($product)
+ {
// Check if event is enabled
if (!$this->is_event_enabled('low_stock', 'email', 'staff')) {
return;
}
-
- // Send email
- $this->send_email('low_stock', 'staff', $product);
+
+ // Pass low_stock_threshold so template can display it
+ $low_stock_threshold = get_option('woocommerce_notify_low_stock_amount', 2);
+ $this->send_email('low_stock', 'staff', $product, [
+ 'low_stock_threshold' => $low_stock_threshold,
+ ]);
}
-
+
/**
* Send out of stock email
*
* @param WC_Product $product
*/
- public function send_out_of_stock_email($product) {
+ public function send_out_of_stock_email($product)
+ {
// Check if event is enabled
if (!$this->is_event_enabled('out_of_stock', 'email', 'staff')) {
return;
}
-
+
// Send email
$this->send_email('out_of_stock', 'staff', $product);
}
-
+
/**
* Check stock levels when product stock is updated
*
* @param WC_Product $product
*/
- public function check_stock_levels($product) {
+ public function check_stock_levels($product)
+ {
$stock = $product->get_stock_quantity();
$low_stock_threshold = get_option('woocommerce_notify_low_stock_amount', 2);
-
+
if ($stock <= 0) {
$this->send_out_of_stock_email($product);
} elseif ($stock <= $low_stock_threshold) {
$this->send_low_stock_email($product);
}
}
-
+
/**
* Check if event is enabled
*
@@ -466,14 +489,15 @@ class EmailManager {
* @param string $recipient_type
* @return bool
*/
- private function is_event_enabled($event_id, $channel_id, $recipient_type) {
+ private function is_event_enabled($event_id, $channel_id, $recipient_type)
+ {
$settings = get_option('woonoow_notification_settings', []);
-
+
// Check if event exists and channel is configured
if (isset($settings['events'][$event_id]['channels'][$channel_id])) {
return $settings['events'][$event_id]['channels'][$channel_id]['enabled'] ?? false;
}
-
+
// Default: enable email notifications if not explicitly configured
// This allows the plugin to work out-of-the-box with default templates
if ($channel_id === 'email') {
@@ -481,10 +505,10 @@ class EmailManager {
}
return true; // Enable by default
}
-
+
return false;
}
-
+
/**
* Send email
*
@@ -493,36 +517,37 @@ class EmailManager {
* @param mixed $data
* @param array $extra_data
*/
- private function send_email($event_id, $recipient_type, $data, $extra_data = []) {
+ private function send_email($event_id, $recipient_type, $data, $extra_data = [])
+ {
if (defined('WP_DEBUG') && WP_DEBUG) {
}
-
+
// Get email renderer
$renderer = EmailRenderer::instance();
-
+
// Render email
$email = $renderer->render($event_id, $recipient_type, $data, $extra_data);
-
+
if (!$email) {
if (defined('WP_DEBUG') && WP_DEBUG) {
}
return;
}
-
+
if (defined('WP_DEBUG') && WP_DEBUG) {
}
-
+
// Send email via wp_mail
$headers = [
'Content-Type: text/html; charset=UTF-8',
'From: ' . get_bloginfo('name') . ' <' . get_option('admin_email') . '>',
];
-
+
$sent = wp_mail($email['to'], $email['subject'], $email['body'], $headers);
-
+
if (defined('WP_DEBUG') && WP_DEBUG) {
}
-
+
// Log email sent
do_action('woonoow_email_sent', $event_id, $recipient_type, $email);
}
diff --git a/includes/Core/Notifications/EmailRenderer.php b/includes/Core/Notifications/EmailRenderer.php
index e9f223e..8e5a32f 100644
--- a/includes/Core/Notifications/EmailRenderer.php
+++ b/includes/Core/Notifications/EmailRenderer.php
@@ -227,6 +227,7 @@ class EmailRenderer
'payment_method' => $data->get_payment_method_title(),
'payment_status' => $data->get_status(),
'payment_date' => $payment_date,
+ 'payment_error_reason' => $data->get_meta('_payment_error_reason') ?: 'Payment declined',
'transaction_id' => $data->get_transaction_id() ?: 'N/A',
'shipping_method' => $data->get_shipping_method(),
'estimated_delivery' => $estimated_delivery,
@@ -239,9 +240,12 @@ class EmailRenderer
'billing_address' => $data->get_formatted_billing_address(),
'shipping_address' => $data->get_formatted_shipping_address(),
// URLs
- 'review_url' => $data->get_view_order_url(), // Can be customized later
+ 'review_url' => $data->get_view_order_url(),
+ 'return_url' => $data->get_view_order_url(), // Customers click to initiate return
+ 'contact_url' => home_url('/contact'),
'shop_url' => get_permalink(wc_get_page_id('shop')),
'my_account_url' => get_permalink(wc_get_page_id('myaccount')),
+ 'account_url' => get_permalink(wc_get_page_id('myaccount')), // Alias for my_account_url
'payment_retry_url' => $data->get_checkout_payment_url(),
// Tracking (if available from meta)
'tracking_number' => $data->get_meta('_tracking_number') ?: 'N/A',
@@ -249,6 +253,7 @@ class EmailRenderer
'shipping_carrier' => $data->get_meta('_shipping_carrier') ?: 'Standard Shipping',
]);
+
// Order items table
$items_html = '';
$items_html .= '';
@@ -277,9 +282,10 @@ class EmailRenderer
$items_html .= '
';
- // Both naming conventions for compatibility
+ // All naming conventions for compatibility
$variables['order_items'] = $items_html;
$variables['order_items_table'] = $items_html;
+ $variables['order_items_list'] = $items_html; // Alias used in some templates
}
// Product variables
diff --git a/includes/Frontend/Assets.php b/includes/Frontend/Assets.php
index 4c2cd84..162fa0f 100644
--- a/includes/Frontend/Assets.php
+++ b/includes/Frontend/Assets.php
@@ -19,6 +19,12 @@ class Assets
add_action('wp_enqueue_scripts', [self::class, 'dequeue_conflicting_scripts'], 100);
add_filter('script_loader_tag', [self::class, 'add_module_type'], 10, 3);
add_action('woocommerce_before_main_content', [self::class, 'inject_spa_mount_point'], 5);
+
+ // Hide admin bar if configured
+ $settings = get_option('woonoow_appearance_settings', []);
+ if (!empty($settings['general']['hide_admin_bar'])) {
+ add_filter('show_admin_bar', '__return_false');
+ }
}
/**
@@ -115,13 +121,15 @@ class Assets
return;
}
- // Check if we're in full mode and not on a page with shortcode
- $spa_settings = get_option('woonoow_customer_spa_settings', []);
- $mode = isset($spa_settings['mode']) ? $spa_settings['mode'] : 'disabled';
+ // Get appearance settings for unified spa_mode check
+ $appearance_settings = get_option('woonoow_appearance_settings', []);
+ $spa_mode = $appearance_settings['general']['spa_mode'] ?? 'full';
- if ($mode === 'full') {
+ if ($spa_mode === 'full') {
// Only inject if the mount point doesn't already exist (from shortcode)
- echo '';
+ $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
+ $current_path = parse_url($request_uri, PHP_URL_PATH);
+ echo '';
}
}
@@ -227,6 +235,14 @@ class Assets
// If SPA Entry Page is WP frontpage, base path is /, otherwise use Entry Page slug
$base_path = $is_spa_wp_frontpage ? '' : ($spa_page ? '/' . $spa_page->post_name : '/store');
+ // When injecting into a CPT or structural page, the URL does not start with the SPA base path.
+ // E.g., /desain-mockup... instead of /store/desain-mockup...
+ // For these pages, we must force the base path to empty so BrowserRouter starts from the root.
+ if (is_singular() && (!isset($spa_page) || get_queried_object_id() !== $spa_page->ID)) {
+ // If we're on a singular page that isn't the SPA Entry Page, it's a structural page or CPT
+ $base_path = '';
+ }
+
// Check if BrowserRouter is enabled (default: true for SEO)
$use_browser_router = $appearance_settings['general']['use_browser_router'] ?? true;
@@ -275,20 +291,27 @@ class Assets
}
/**
- * Check if we should load customer-spa assets
+ * Check if we should load assets on this page
*/
- private static function should_load_assets()
+ public static function should_load_assets()
{
- global $post;
+ // Don't load on admin pages
+ if (is_admin()) {
+ return false;
+ }
- // Check if we're serving SPA directly (set by serve_spa_for_frontpage_routes)
+ // Force load if constant is defined (e.g. for preview)
if (defined('WOONOOW_SERVE_SPA') && WOONOOW_SERVE_SPA) {
return true;
}
- // Check if we're on a frontpage SPA route (by URL detection)
- if (self::is_frontpage_spa_route()) {
- return true;
+ // Get SPA mode from appearance settings
+ $appearance_settings = get_option('woonoow_appearance_settings', []);
+ $mode = $appearance_settings['general']['spa_mode'] ?? 'full';
+
+ // Check if SPA is completely disabled
+ if ($mode === 'disabled') {
+ return false;
}
// First check: Is this a designated SPA page?
@@ -296,39 +319,29 @@ class Assets
return true;
}
- // Get SPA mode from appearance settings (the correct source)
- $appearance_settings = get_option('woonoow_appearance_settings', []);
- $mode = $appearance_settings['general']['spa_mode'] ?? 'full';
+ // Check if we're on a frontpage SPA route
+ if (self::is_frontpage_spa_route()) {
+ return true;
+ }
- // If disabled, only load for pages with shortcodes
- if ($mode === 'disabled') {
- // Special handling for WooCommerce Shop page (it's an archive, not a regular post)
- if (function_exists('is_shop') && is_shop()) {
- $shop_page_id = get_option('woocommerce_shop_page_id');
- if ($shop_page_id) {
- $shop_page = get_post($shop_page_id);
- if ($shop_page && has_shortcode($shop_page->post_content, 'woonoow_shop')) {
- return true;
- }
- }
+ // For structural pages (is_singular('page'))
+ if (is_singular('page')) {
+ $page_id = get_queried_object_id();
+ $structure = get_post_meta($page_id, '_wn_page_structure', true);
+ if (!empty($structure) && !empty($structure['sections'])) {
+ return true;
}
+ }
- // Check for shortcodes on regular pages
- if ($post) {
- if (has_shortcode($post->post_content, 'woonoow_shop')) {
- return true;
- }
- if (has_shortcode($post->post_content, 'woonoow_cart')) {
- return true;
- }
- if (has_shortcode($post->post_content, 'woonoow_checkout')) {
- return true;
- }
- if (has_shortcode($post->post_content, 'woonoow_account')) {
+ // For CPTs with WooNooW templates
+ if (is_singular() && !is_singular('page')) {
+ $post_type = get_post_type();
+ if (!in_array($post_type, ['product', 'shop_order', 'shop_coupon'])) {
+ $wn_template = get_option("wn_template_{$post_type}", null);
+ if (!empty($wn_template) && !empty($wn_template['sections'])) {
return true;
}
}
- return false;
}
// Full SPA mode - load on all WooCommerce pages
@@ -353,6 +366,7 @@ class Assets
// Checkout-Only mode - load only on specific pages
if ($mode === 'checkout_only') {
+ $spa_settings = get_option('woonoow_customer_spa_settings', []);
$checkout_pages = isset($spa_settings['checkoutPages']) ? $spa_settings['checkoutPages'] : [];
if (!empty($checkout_pages['checkout']) && function_exists('is_checkout') && is_checkout() && !is_order_received_page()) {
@@ -370,6 +384,7 @@ class Assets
return false;
}
+ global $post;
// Check if current page has WooNooW shortcodes
if ($post && has_shortcode($post->post_content, 'woonoow_shop')) {
return true;
diff --git a/includes/Frontend/ShopController.php b/includes/Frontend/ShopController.php
index 18e3edc..dec4283 100644
--- a/includes/Frontend/ShopController.php
+++ b/includes/Frontend/ShopController.php
@@ -283,8 +283,8 @@ class ShopController
// Add detailed info if requested
if ($detailed) {
- $data['description'] = $product->get_description();
- $data['short_description'] = $product->get_short_description();
+ $data['description'] = wpautop($product->get_description());
+ $data['short_description'] = wpautop($product->get_short_description());
$data['sku'] = $product->get_sku();
$data['tags'] = wp_get_post_terms($product->get_id(), 'product_tag', ['fields' => 'names']);
diff --git a/includes/Frontend/TemplateOverride.php b/includes/Frontend/TemplateOverride.php
index cc65387..1736363 100644
--- a/includes/Frontend/TemplateOverride.php
+++ b/includes/Frontend/TemplateOverride.php
@@ -171,6 +171,11 @@ class TemplateOverride
'index.php?page_id=' . $spa_page_id . '&woonoow_spa_path=reset-password',
'top'
);
+ add_rewrite_rule(
+ '^subscribe/?$',
+ 'index.php?page_id=' . $spa_page_id . '&woonoow_spa_path=subscribe',
+ 'top'
+ );
// /order-pay/* → SPA page
add_rewrite_rule(
@@ -352,7 +357,6 @@ class TemplateOverride
if ($post->ID == $spa_page_id || $post->ID == $frontpage_id) {
return;
}
-
// Check if page has WooNooW structure
$structure = get_post_meta($post->ID, '_wn_page_structure', true);
if (!empty($structure) && !empty($structure['sections'])) {
@@ -364,11 +368,6 @@ class TemplateOverride
}
}
- /**
- * Serve SPA template directly for frontpage SPA routes
- * When SPA page is set as WordPress frontpage, intercept known routes
- * and serve the SPA template directly (bypasses WooCommerce templates)
- */
/**
* Serve SPA template directly for frontpage SPA routes
* When SPA page is set as WordPress frontpage, intercept known routes
@@ -417,8 +416,8 @@ class TemplateOverride
'/my-account', // Account page
'/login', // Login page
'/register', // Register page
- '/register', // Register page
'/reset-password', // Password reset
+ '/subscribe', // Subscribe page
'/order-pay', // Order pay page
];
@@ -535,6 +534,32 @@ class TemplateOverride
}
}
+ // Check if it's a structural page with WooNooW sections
+ if (is_singular('page')) {
+ $page_id = get_queried_object_id();
+ $structure = get_post_meta($page_id, '_wn_page_structure', true);
+ if (!empty($structure) && !empty($structure['sections'])) {
+ $spa_template = plugin_dir_path(dirname(dirname(__FILE__))) . 'templates/spa-full-page.php';
+ if (file_exists($spa_template)) {
+ return $spa_template;
+ }
+ }
+ }
+
+ // Check if it's a CPT singular with a WooNooW template
+ if (is_singular() && !is_singular('page')) {
+ $post_type = get_post_type();
+ if ($post_type) {
+ $cpt_template = get_option("wn_template_{$post_type}", null);
+ if (!empty($cpt_template) && !empty($cpt_template['sections'])) {
+ $spa_template = plugin_dir_path(dirname(dirname(__FILE__))) . 'templates/spa-full-page.php';
+ if (file_exists($spa_template)) {
+ return $spa_template;
+ }
+ }
+ }
+ }
+
// For spa_mode = 'full', override WooCommerce pages
if ($spa_mode === 'full') {
// Override all WooCommerce pages
@@ -569,23 +594,30 @@ class TemplateOverride
return;
}
- // Determine page type
- $page_type = 'shop';
+ // Determine page type and route
$data_attrs = 'data-page="shop"';
+ // Pass current request URI as initial route so router doesn't fallback to /shop
+ $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
+ $current_path = parse_url($request_uri, PHP_URL_PATH);
+ $data_attrs .= ' data-initial-route="' . esc_attr($current_path) . '"';
+
if (is_product()) {
- $page_type = 'product';
global $post;
- $data_attrs = 'data-page="product" data-product-id="' . esc_attr($post->ID) . '"';
+ $data_attrs .= ' data-page="product" data-product-id="' . esc_attr($post->ID) . '"';
} elseif (is_cart()) {
- $page_type = 'cart';
- $data_attrs = 'data-page="cart"';
+ $data_attrs .= ' data-page="cart"';
} elseif (is_checkout()) {
- $page_type = 'checkout';
- $data_attrs = 'data-page="checkout"';
+ $data_attrs .= ' data-page="checkout"';
} elseif (is_account_page()) {
- $page_type = 'account';
- $data_attrs = 'data-page="account"';
+ $data_attrs .= ' data-page="account"';
+ } elseif (is_singular('page')) {
+ $data_attrs .= ' data-page="page"';
+ } elseif (is_singular() && !is_singular('page')) {
+ // CPT single item with a WooNooW template
+ global $post;
+ $post_type = get_post_type();
+ $data_attrs .= ' data-page="cpt" data-cpt-type="' . esc_attr($post_type) . '" data-cpt-slug="' . esc_attr($post->post_name) . '"';
}
// Output SPA mount point
@@ -631,6 +663,26 @@ class TemplateOverride
return true;
}
+ // For structural pages (is_singular('page'))
+ if (is_singular('page')) {
+ $page_id = get_queried_object_id();
+ $structure = get_post_meta($page_id, '_wn_page_structure', true);
+ if (!empty($structure) && !empty($structure['sections'])) {
+ return true;
+ }
+ }
+
+ // For CPT singular items with a WooNooW template
+ if (is_singular() && !is_singular('page')) {
+ $post_type = get_post_type();
+ if ($post_type) {
+ $cpt_template = get_option("wn_template_{$post_type}", null);
+ if (!empty($cpt_template) && !empty($cpt_template['sections'])) {
+ return true;
+ }
+ }
+ }
+
return false;
}
diff --git a/includes/Templates/TemplateRegistry.php b/includes/Templates/TemplateRegistry.php
index 5264459..7b50f8a 100644
--- a/includes/Templates/TemplateRegistry.php
+++ b/includes/Templates/TemplateRegistry.php
@@ -39,6 +39,13 @@ class TemplateRegistry
'description' => 'Simple contact page with a form and address details.',
'icon' => 'mail',
'sections' => self::get_contact_structure()
+ ],
+ [
+ 'id' => 'single-post',
+ 'label' => 'Single Post / CPT',
+ 'description' => 'A dynamic layout for blog posts or custom post types with a hero, featured image, and body content.',
+ 'icon' => 'layout',
+ 'sections' => self::get_single_post_structure()
]
]);
}
@@ -166,4 +173,73 @@ class TemplateRegistry
]
];
}
+
+ private static function get_single_post_structure()
+ {
+ return [
+ // ── Section 1: Article Hero ─────────────────────────────────────
+ [
+ 'id' => self::generate_id(),
+ 'type' => 'hero',
+ 'layoutVariant' => 'centered',
+ 'colorScheme' => 'default',
+ 'props' => [
+ 'title' => ['type' => 'dynamic', 'source' => 'post_title'],
+ 'subtitle' => ['type' => 'dynamic', 'source' => 'post_author'],
+ 'image' => ['type' => 'static', 'value' => ''],
+ 'cta_text' => ['type' => 'static', 'value' => ''],
+ 'cta_url' => ['type' => 'static', 'value' => ''],
+ ],
+ // dynamicBackground tells the API to resolve styles.backgroundImage
+ // from 'post_featured_image' at render time (falls back to '' if no featured image)
+ 'styles' => [
+ 'contentWidth' => 'contained',
+ 'heightPreset' => 'medium',
+ 'dynamicBackground' => 'post_featured_image',
+ 'backgroundOverlay' => 50,
+ ],
+ ],
+
+ // ── Section 2: Article Body ─────────────────────────────────────
+ [
+ 'id' => self::generate_id(),
+ 'type' => 'content',
+ 'layoutVariant' => 'narrow',
+ 'colorScheme' => 'default',
+ 'props' => [
+ 'content' => ['type' => 'dynamic', 'source' => 'post_content'],
+ 'cta_text' => ['type' => 'static', 'value' => ''],
+ 'cta_url' => ['type' => 'static', 'value' => ''],
+ ],
+ 'styles' => ['contentWidth' => 'contained', 'heightPreset' => 'default'],
+ ],
+
+ // ── Section 3: Related Posts ────────────────────────────────────
+ [
+ 'id' => self::generate_id(),
+ 'type' => 'feature-grid',
+ 'layoutVariant' => 'grid-3',
+ 'colorScheme' => 'muted',
+ 'props' => [
+ 'heading' => ['type' => 'static', 'value' => 'Related Articles'],
+ 'features' => ['type' => 'dynamic', 'source' => 'related_posts'],
+ ],
+ 'styles' => ['contentWidth' => 'contained', 'heightPreset' => 'default'],
+ ],
+
+ // ── Section 4: CTA Banner ───────────────────────────────────────
+ [
+ 'id' => self::generate_id(),
+ 'type' => 'cta-banner',
+ 'colorScheme' => 'gradient',
+ 'props' => [
+ 'title' => ['type' => 'static', 'value' => 'Enjoyed this article?'],
+ 'text' => ['type' => 'static', 'value' => 'Subscribe to our newsletter and never miss an update.'],
+ 'button_text' => ['type' => 'static', 'value' => 'Subscribe Now'],
+ 'button_url' => ['type' => 'static', 'value' => '/subscribe'],
+ ],
+ 'styles' => ['contentWidth' => 'contained', 'heightPreset' => 'medium'],
+ ],
+ ];
+ }
}
diff --git a/templates/spa-full-page.php b/templates/spa-full-page.php
index bb6c435..5bdba86 100644
--- a/templates/spa-full-page.php
+++ b/templates/spa-full-page.php
@@ -1,41 +1,65 @@
>
+
+
>
ID) . '"';
+ } elseif (is_cart()) {
+ $data_attrs = 'data-page="cart"';
+ } elseif (is_checkout()) {
+ $data_attrs = 'data-page="checkout"';
+ } elseif (is_account_page()) {
+ $data_attrs = 'data-page="account"';
+ } elseif (is_singular('page')) {
+ $data_attrs = 'data-page="page"';
+ } elseif (is_singular() && !is_singular('page')) {
+ global $post;
+ $post_type = get_post_type();
+ $data_attrs = 'data-page="cpt" data-cpt-type="' . esc_attr($post_type) . '" data-cpt-slug="' . esc_attr($post->post_name) . '"';
+ } else {
+ $data_attrs = 'data-page="shop"';
+ }
+
// If this is the front page, route to /
if (is_front_page()) {
- $data_attrs = 'data-page="shop" data-initial-route="/"';
+ $data_attrs .= ' data-initial-route="/"';
} else {
- $data_attrs = 'data-page="shop" data-initial-route="/shop"';
+ $data_attrs .= ' data-initial-route="' . esc_attr($current_path) . '"';
}
}
?>
-
+
-
+
-
+
+