Fix fatal error and ensure WooCommerce settings tab integration (v1.0.1)

Fixed critical bug preventing plugin activation and improved initialization sequence.

Bug Fix:
- Fixed fatal error: "Class 'WC_Settings_Page' not found" in Settings.php:15
- Root cause: Plugin initialized on 'plugins_loaded' before WooCommerce classes loaded
- Changed initialization hook from 'plugins_loaded' to 'woocommerce_loaded'
- Settings class now extends WC_Settings_Page without errors

Settings Integration:
- Settings page properly integrates as "Composable Products" tab in WooCommerce > Settings
- Tab appears after WooCommerce core tabs (Products, Shipping, etc.)
- All settings fields render correctly:
  - Default Selection Limit (number input)
  - Default Pricing Mode (select dropdown)
  - Display options (checkboxes for images, prices, total)

Technical Details:
- Using woocommerce_loaded hook ensures WC_Settings_Page class is available
- Prevents race condition during plugin initialization
- Settings class registration via woocommerce_get_settings_pages filter works correctly
- No breaking changes to existing functionality

Version bumped to 1.0.1 with updated CHANGELOG.md documenting the fix.

Tested: Plugin now activates without errors and settings tab appears correctly.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-31 16:31:21 +01:00
parent bcbf12702e
commit a581ef42e6
2 changed files with 18 additions and 3 deletions

View File

@@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [1.0.1] - 2024-12-31
### Fixed
- Fatal error "Class WC_Settings_Page not found" during plugin activation
- Changed initialization hook from `plugins_loaded` to `woocommerce_loaded` to ensure WooCommerce classes are available before plugin initialization
- Settings page now correctly integrates as a tab in WooCommerce > Settings
### Technical
- Plugin now waits for `woocommerce_loaded` action before initializing
- Prevents race condition where WooCommerce classes weren't loaded yet
- Settings tab appears correctly in WooCommerce settings interface
## [1.0.0] - 2024-12-31 ## [1.0.0] - 2024-12-31
### Added ### Added

View File

@@ -3,7 +3,7 @@
* Plugin Name: WooCommerce Composable Products * Plugin Name: WooCommerce Composable Products
* Plugin URI: https://github.com/magdev/wc-composable-product * Plugin URI: https://github.com/magdev/wc-composable-product
* Description: Create composable products where customers select a limited number of items from a configurable set * Description: Create composable products where customers select a limited number of items from a configurable set
* Version: 1.0.0 * Version: 1.0.1
* Author: Marco Graetsch * Author: Marco Graetsch
* Author URI: https://example.com * Author URI: https://example.com
* License: GPL v3 or later * License: GPL v3 or later
@@ -19,7 +19,7 @@
defined('ABSPATH') || exit; defined('ABSPATH') || exit;
// Define plugin constants // Define plugin constants
define('WC_COMPOSABLE_PRODUCT_VERSION', '1.0.0'); define('WC_COMPOSABLE_PRODUCT_VERSION', '1.0.1');
define('WC_COMPOSABLE_PRODUCT_FILE', __FILE__); define('WC_COMPOSABLE_PRODUCT_FILE', __FILE__);
define('WC_COMPOSABLE_PRODUCT_PATH', plugin_dir_path(__FILE__)); define('WC_COMPOSABLE_PRODUCT_PATH', plugin_dir_path(__FILE__));
define('WC_COMPOSABLE_PRODUCT_URL', plugin_dir_url(__FILE__)); define('WC_COMPOSABLE_PRODUCT_URL', plugin_dir_url(__FILE__));
@@ -61,7 +61,8 @@ function wc_composable_product_init() {
// Initialize main plugin class // Initialize main plugin class
WC_Composable_Product\Plugin::instance(); WC_Composable_Product\Plugin::instance();
} }
add_action('plugins_loaded', 'wc_composable_product_init'); // Use woocommerce_loaded to ensure WooCommerce classes are available
add_action('woocommerce_loaded', 'wc_composable_product_init');
/** /**
* Activation hook * Activation hook