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() { ?>