load_settings(); } /** * Load settings from database */ private function load_settings() { $stored_settings = get_option(self::OPTION_NAME, array()); $default_settings = $this->get_default_settings(); // Merge stored settings with defaults to ensure all keys exist $this->settings = wp_parse_args($stored_settings, $default_settings); // Ensure show_on_loop defaults to 'yes' if (empty($this->settings['show_on_loop'])) { $this->settings['show_on_loop'] = 'yes'; } } /** * Get all default settings */ private function get_default_settings() { return array( // General Settings 'enabled' => 'yes', 'enable_for_guests' => 'yes', 'cookie_expiration' => '30', 'enable_multiple' => 'no', 'auto_category' => 'no', 'max_per_user' => '10', 'default_privacy' => 'public', 'remove_on_purchase' => 'yes', 'wishlist_page_id' => '', // WooCommerce My Account Settings 'enable_my_account_tab' => 'yes', 'my_account_tab_title' => 'My Wishlists', 'my_account_tab_endpoint' => 'my-wishlists', // Display Settings 'button_position' => 'after_add_to_cart', 'button_text' => 'Add to Wishlist', 'button_icon' => 'heart', 'show_on_loop' => 'yes', 'loop_position' => 'after_add_to_cart', 'redirect_after_add' => 'no', 'enable_ajax' => 'yes', 'wishlist_layout' => 'grid', 'wishlist_template' => 'default', 'products_per_page' => '12', // Wishlist Detail Page Settings (Advanced Template) 'show_product_variations' => 'yes', 'show_product_price' => 'yes', 'show_price_variation' => 'yes', 'show_product_quantity' => 'yes', 'show_product_stock' => 'yes', 'show_date_added' => 'yes', 'show_add_to_cart' => 'yes', 'show_checkbox_select' => 'yes', 'show_remove_icon' => 'yes', // Cart Save for Later Settings 'enable_cart_save_for_later' => 'yes', 'save_for_later_btn_text' => 'Save for Later', 'saved_for_later_heading' => 'Saved for Later', // Mini-Wishlist & Slide-in Drawer Settings 'enable_mini_wishlist' => 'yes', 'enable_floating_wishlist_btn' => 'yes', 'floating_wishlist_btn_pos' => 'bottom-right', 'mini_wishlist_auto_open_on_add' => 'yes', 'mini_wishlist_show_add_to_cart' => 'yes', // Estimate & Quote Settings 'enable_quote_requests' => 'yes', 'quote_button_text' => 'Request an Estimate / Quote', 'quote_recipient_email' => '', 'quote_require_phone' => 'no', 'quote_show_in_drawer' => 'yes', 'quote_success_message' => 'Thank you! Your quote request has been sent. We will get back to you with custom pricing shortly.', // Wishlist Management Page Color Settings 'wishlist_page_title_color' => '#111827', 'wishlist_page_card_bg' => '#ffffff', 'wishlist_page_text_color' => '#6b7280', 'wishlist_page_button_bg' => '#007cba', 'wishlist_page_button_text' => '#ffffff', // Default Wishlist Template Settings 'default_product_image_width' => '150', 'default_product_image_height' => '150', 'default_card_spacing' => '20', 'default_border_radius' => '8', 'default_items_per_row' => '3', 'default_show_product_name' => 'yes', 'default_show_product_price' => 'yes', 'default_show_stock_status' => 'yes', 'default_show_add_to_cart' => 'yes', 'default_show_remove_btn' => 'yes', // Advanced Wishlist Template Settings 'advanced_product_image_width' => '280', 'advanced_product_image_height' => '280', 'advanced_card_spacing' => '24', 'advanced_border_radius' => '12', 'advanced_items_per_row' => '3', 'advanced_page_title' => 'My Wishlist', 'advanced_page_title_color' => '#e97730', 'advanced_page_title_bg_color' => 'transparent', 'advanced_item_count_text' => 'items', 'advanced_item_count_color' => '#e97730', 'advanced_card_bg_color' => '#ffffff', 'advanced_card_title_color' => '#000000', 'advanced_price_color' => '#000000', 'advanced_stock_in_color' => '#16a34a', 'advanced_stock_out_color' => '#dc2626', // Popup Customization Settings 'popup_mode' => 'both', 'popup_show_create' => 'yes', 'popup_show_search' => 'yes', 'popup_privacy_options' => 'all', 'popup_show_categories' => 'yes', 'popup_primary_color' => '#2271b1', 'popup_header_bg' => '#f9fafb', 'popup_header_text' => '#1f2937', 'popup_bg_color' => '#ffffff', 'popup_text_color' => '#4b5563', 'popup_border_color' => '#e5e7eb', 'popup_icon_color' => '#6b7280', 'popup_width' => '420', 'popup_border_radius' => '8', // Social Settings 'enable_share' => 'yes', 'share_platforms' => array('facebook', 'twitter', 'whatsapp', 'email', 'copy_link'), 'share_style' => 'icons', 'share_position' => 'before_table', 'og_tags' => 'yes', // Email Settings 'enable_emails' => 'yes', 'price_drop_notification' => 'yes', 'stock_notification' => 'yes', 'promotional_emails' => 'no', 'email_from_name' => get_bloginfo('name'), 'email_from_address' => get_option('admin_email'), 'email_footer' => '', // Advanced Settings 'custom_css' => '', 'debug_mode' => 'no', 'cache_duration' => '3600', 'remove_data_on_uninstall' => 'no', ); } /** * Get all settings */ public function get_all_settings() { return $this->settings; } /** * Get a setting value */ public function get($key, $default = null) { // First check if it exists in our settings array if (isset($this->settings[$key])) { return $this->settings[$key]; } // For backward compatibility, check old WooCommerce option $wc_option = get_option('aicoso_wishlist_' . $key, null); if ($wc_option !== null) { return $wc_option; } // Return default if provided if ($default !== null) { return $default; } // Return from default settings $defaults = $this->get_default_settings(); return isset($defaults[$key]) ? $defaults[$key] : null; } /** * Set a setting value */ public function set($key, $value) { $this->settings[$key] = $value; } /** * Save all settings */ public function save() { // Keep legacy option and default wishlists in sync if (isset($this->settings['default_privacy'])) { update_option('aicoso_wishlist_default_privacy', $this->settings['default_privacy']); global $wpdb; $wishlists_table = $wpdb->prefix . AICOSO_WISHLIST_TABLE_WISHLISTS; $wpdb->query($wpdb->prepare( "UPDATE {$wishlists_table} SET privacy = %s WHERE is_default = 1", $this->settings['default_privacy'] )); } // Keep legacy show_on_loop option in sync if (isset($this->settings['show_on_loop'])) { update_option('aicoso_wishlist_show_on_loop', $this->settings['show_on_loop']); } // Save to our option return update_option(self::OPTION_NAME, $this->settings); } /** * Migrate settings from WooCommerce */ private function migrate_wc_settings() { $migrated = get_option('aicoso_wishlist_migrated', false); if (!$migrated) { $mapping = array( 'aicoso_wishlist_enabled' => 'enabled', 'aicoso_wishlist_enable_for_guests' => 'enable_for_guests', 'aicoso_wishlist_cookie_expiration' => 'cookie_expiration', 'aicoso_wishlist_enable_multiple' => 'enable_multiple', 'aicoso_wishlist_auto_category' => 'auto_category', 'aicoso_wishlist_max_per_user' => 'max_per_user', 'aicoso_wishlist_default_privacy' => 'default_privacy', 'aicoso_wishlist_remove_on_purchase' => 'remove_on_purchase', 'aicoso_wishlist_page_id' => 'wishlist_page_id', 'aicoso_wishlist_button_position' => 'button_position', 'aicoso_wishlist_button_text' => 'button_text', 'aicoso_wishlist_button_icon' => 'button_icon', 'aicoso_wishlist_show_on_loop' => 'show_on_loop', 'aicoso_wishlist_loop_position' => 'loop_position', 'aicoso_wishlist_redirect_after_add' => 'redirect_after_add', 'aicoso_wishlist_enable_ajax' => 'enable_ajax', 'aicoso_wishlist_layout' => 'wishlist_layout', 'aicoso_wishlist_per_page' => 'products_per_page', 'aicoso_wishlist_enable_share' => 'enable_share', 'aicoso_wishlist_share_platforms' => 'share_platforms', 'aicoso_wishlist_share_style' => 'share_style', 'aicoso_wishlist_share_position' => 'share_position', 'aicoso_wishlist_og_tags' => 'og_tags', 'aicoso_wishlist_enable_emails' => 'enable_emails', 'aicoso_wishlist_price_drop_notification' => 'price_drop_notification', 'aicoso_wishlist_stock_notification' => 'stock_notification', 'aicoso_wishlist_promotional_emails' => 'promotional_emails', 'aicoso_wishlist_email_from_name' => 'email_from_name', 'aicoso_wishlist_email_from_address' => 'email_from_address', 'aicoso_wishlist_email_footer' => 'email_footer', 'aicoso_wishlist_custom_css' => 'custom_css', 'aicoso_wishlist_debug' => 'debug_mode', 'aicoso_wishlist_cache_duration' => 'cache_duration', 'aicoso_wishlist_remove_data_on_uninstall' => 'remove_data_on_uninstall', ); foreach ($mapping as $old_key => $new_key) { $old_value = get_option($old_key, null); if ($old_value !== null) { $this->settings[$new_key] = $old_value; } } // Mark as migrated update_option('aicoso_wishlist_migrated', true); } } /** * Render general settings section */ public function render_general_settings() { ?>

get('enabled'), 'yes'); ?>>

get('enable_for_guests'), 'yes'); ?>>

get('remove_on_purchase'), 'yes'); ?>>

get('enable_multiple'), 'yes'); ?>>

get('auto_category'), 'yes'); ?>>

'settings[wishlist_page_id]', 'id' => 'wishlist_page_id', 'selected' => $this->get('wishlist_page_id'), 'show_option_none' => __('— Select —', 'aicoso-wishlist-for-woocommerce'), 'option_none_value' => '', 'class' => '', 'style' => 'width: 100%; padding: 6px 10px; font-size: 13px; border-radius: 6px; border: 2px solid #e5e7eb;' )); ?>

get('enable_my_account_tab', 'yes'), 'yes'); ?>>

Real-time

get('show_on_loop', 'yes'), 'yes'); ?>>

get('redirect_after_add', 'no'), 'yes'); ?>>
get('enable_ajax', 'yes'), 'yes'); ?>>

get('enable_cart_save_for_later', 'yes'), 'yes'); ?>>

get('enable_mini_wishlist', 'yes'), 'yes'); ?>>
get('enable_floating_wishlist_btn', 'yes'), 'yes'); ?>>
get('mini_wishlist_auto_open_on_add', 'yes'), 'yes'); ?>>
get('mini_wishlist_show_add_to_cart', 'yes'), 'yes'); ?>>

get('enable_quote_requests', 'yes'), 'yes'); ?>>
get('quote_show_in_drawer', 'yes'), 'yes'); ?>>
get('quote_require_phone', 'no'), 'yes'); ?>>

get('wishlist_template', 'default'), 'advanced'); ?>>

Real-time

3 items Public

get('default_show_product_name', 'yes'), 'yes'); ?>>
get('default_show_product_price', 'yes'), 'yes'); ?>>
get('default_show_stock_status', 'yes'), 'yes'); ?>>
get('default_show_add_to_cart', 'yes'), 'yes'); ?>>
get('default_show_remove_btn', 'yes'), 'yes'); ?>>

get('show_product_variations', 'yes'), 'yes'); ?>>
get('show_product_price', 'yes'), 'yes'); ?>>
get('show_price_variation', 'yes'), 'yes'); ?>>
get('show_product_quantity', 'yes'), 'yes'); ?>>
get('show_product_stock', 'yes'), 'yes'); ?>>
get('show_date_added', 'yes'), 'yes'); ?>>
get('show_add_to_cart', 'yes'), 'yes'); ?>>
get('show_checkbox_select', 'yes'), 'yes'); ?>>
get('show_remove_icon', 'yes'), 'yes'); ?>>

get('popup_show_create', 'yes'), 'yes'); ?>>
get('popup_show_search', 'yes'), 'yes'); ?>>
get('popup_show_categories', 'yes'), 'yes'); ?>>

get('enable_share'), 'yes'); ?>>
get('og_tags'), 'yes'); ?>>

__('Facebook', 'aicoso-wishlist-for-woocommerce'), 'twitter' => __('Twitter', 'aicoso-wishlist-for-woocommerce'), 'pinterest' => __('Pinterest', 'aicoso-wishlist-for-woocommerce'), 'whatsapp' => __('WhatsApp', 'aicoso-wishlist-for-woocommerce'), 'telegram' => __('Telegram', 'aicoso-wishlist-for-woocommerce'), 'linkedin' => __('LinkedIn', 'aicoso-wishlist-for-woocommerce'), 'email' => __('Email', 'aicoso-wishlist-for-woocommerce'), 'copy_link' => __('Copy Link', 'aicoso-wishlist-for-woocommerce'), ); $selected_platforms = $this->get('share_platforms', array()); foreach ($platforms as $value => $label) { $is_checked = in_array($value, (array)$selected_platforms); ?>

get('enable_emails'), 'yes'); ?>>
get('stock_notification'), 'yes'); ?>>
get('price_drop_notification'), 'yes'); ?>>
get('promotional_emails'), 'yes'); ?>>

get('debug_mode'), 'yes'); ?>>
get('remove_data_on_uninstall'), 'yes'); ?>>

load_settings(); $existing_settings = $this->settings; // Store original settings for comparison $original_settings = $existing_settings; // Define all checkbox fields for each tab (these need special handling) $checkbox_fields_by_tab = array( 'general' => array('enabled', 'enable_for_guests', 'remove_on_purchase', 'enable_multiple', 'auto_category', 'enable_my_account_tab'), 'display' => array( 'show_on_loop', 'enable_ajax', 'redirect_after_add', 'enable_cart_save_for_later', 'enable_mini_wishlist', 'enable_floating_wishlist_btn', 'mini_wishlist_auto_open_on_add', 'mini_wishlist_show_add_to_cart', 'enable_quote_requests', 'quote_show_in_drawer', 'quote_require_phone', 'popup_show_create', 'popup_show_search', 'popup_show_categories', 'wishlist_template', 'show_product_variations', 'show_product_price', 'show_price_variation', 'show_product_quantity', 'show_product_stock', 'show_date_added', 'show_add_to_cart', 'show_checkbox_select', 'show_remove_icon', 'default_show_product_name', 'default_show_product_price', 'default_show_stock_status', 'default_show_add_to_cart', 'default_show_remove_btn' ), 'social' => array('enable_share', 'og_tags'), 'email' => array('enable_emails', 'price_drop_notification', 'stock_notification', 'promotional_emails'), 'advanced' => array('debug_mode', 'remove_data_on_uninstall') ); // Get checkbox fields for current tab $checkbox_fields = isset($checkbox_fields_by_tab[$tab]) ? $checkbox_fields_by_tab[$tab] : array(); // Set all checkboxes for current tab to 'no' if not posted foreach ($checkbox_fields as $field) { // Special handling for wishlist_template - it uses 'default' or 'advanced' values if ($field === 'wishlist_template') { if (!isset($posted_settings[$field]) || $posted_settings[$field] !== 'advanced') { $posted_settings[$field] = 'default'; } else { $posted_settings[$field] = 'advanced'; } } else { if (!isset($posted_settings[$field])) { $posted_settings[$field] = 'no'; } else { // Ensure checkbox values are 'yes' when checked $posted_settings[$field] = 'yes'; } } } // Handle array fields (only for social tab) if ($tab === 'social') { if (!isset($posted_settings['share_platforms']) || !is_array($posted_settings['share_platforms'])) { $posted_settings['share_platforms'] = array(); } } // Update settings with posted values foreach ($posted_settings as $key => $value) { if (is_array($value)) { $existing_settings[$key] = array_map('sanitize_text_field', $value); } elseif ($key === 'custom_css' || $key === 'email_footer') { $existing_settings[$key] = wp_kses_post($value); } elseif ($key === 'email_from_address') { $existing_settings[$key] = sanitize_email($value); } else { $existing_settings[$key] = sanitize_text_field($value); } } // Check if settings actually changed $settings_changed = false; foreach ($posted_settings as $key => $value) { $original_value = isset($original_settings[$key]) ? $original_settings[$key] : ''; $new_value = isset($existing_settings[$key]) ? $existing_settings[$key] : ''; // Compare values if (is_array($original_value) && is_array($new_value)) { if (serialize($original_value) !== serialize($new_value)) { $settings_changed = true; break; } } else { if ($original_value !== $new_value) { $settings_changed = true; break; } } } // Update instance settings $this->settings = $existing_settings; // Check if multi-wishlist was disabled $old_multi_enabled = isset($original_settings['enable_multiple']) ? $original_settings['enable_multiple'] : 'no'; $new_multi_enabled = isset($existing_settings['enable_multiple']) ? $existing_settings['enable_multiple'] : 'no'; // Save to database and return status $this->save(); if ($tab === 'general') { flush_rewrite_rules(false); } if ($settings_changed) { // If multi-wishlist was disabled, hide category wishlists (don't move products) if ($old_multi_enabled === 'yes' && $new_multi_enabled === 'no') { $this->hide_category_wishlists(); } // If multi-wishlist was re-enabled, show category wishlists (products already there) if ($old_multi_enabled === 'no' && $new_multi_enabled === 'yes') { $this->show_category_wishlists(); } return array('saved' => true, 'changed' => true); } else { return array('saved' => true, 'changed' => false); } } /** * Hide category wishlists when multi-category is disabled * Products remain in their category wishlists but aren't displayed */ private function hide_category_wishlists() { global $wpdb; $wishlists_table = $wpdb->prefix . AICOSO_WISHLIST_TABLE_WISHLISTS; // Add a 'hidden' flag to all non-default wishlists $wpdb->query(" UPDATE {$wishlists_table} SET wishlist_slug = CONCAT(wishlist_slug, '_hidden') WHERE is_default = 0 AND wishlist_slug NOT LIKE '%_hidden' "); error_log('AICOSO WISHLIST: Category wishlists hidden (multi-category disabled)'); } /** * Show category wishlists when multi-category is re-enabled * Products are already in their category wishlists, just make them visible */ private function show_category_wishlists() { global $wpdb; $wishlists_table = $wpdb->prefix . AICOSO_WISHLIST_TABLE_WISHLISTS; // Remove the '_hidden' flag from all non-default wishlists $wpdb->query(" UPDATE {$wishlists_table} SET wishlist_slug = REPLACE(wishlist_slug, '_hidden', '') WHERE is_default = 0 AND wishlist_slug LIKE '%_hidden' "); error_log('AICOSO WISHLIST: Category wishlists shown (multi-category enabled)'); } } // Initialize global settings instance only if not already set global $aicoso_wishlist_settings; if (!isset($aicoso_wishlist_settings)) { $aicoso_wishlist_settings = new Aicoso_Wishlist_Standalone_Settings(); }