Files
wc-composable-product/wc-composable-product.php
magdev 413b5d8acd Add WooCommerce HPOS compatibility and fix pricing conflicts (v1.1.3)
Fixes WooCommerce compatibility warnings reported by user.

WooCommerce HPOS compatibility:
- Added before_woocommerce_init hook to declare HPOS compatibility
- Declares compatibility with custom_order_tables feature
- Ensures plugin works with WooCommerce's modern order storage

Price calculation improvements:
- Added static flag to prevent multiple executions
- Added composable_price_calculated flag to cart items
- Prevents conflicts with third-party pricing plugins
- Stops other plugins from re-calculating composable product prices

This resolves incompatibility warnings with:
- WooCommerce Analytics
- WooCommerce Update Manager
- Third-party pricing extensions

Files modified:
- wc-composable-product.php: Version 1.1.3, HPOS declaration
- includes/Cart_Handler.php: Improved price calculation guards
- CHANGELOG.md: Documented changes

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-31 17:11:29 +01:00

90 lines
2.8 KiB
PHP

<?php
/**
* Plugin Name: WooCommerce Composable Products
* 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
* Version: 1.1.3
* Author: Marco Graetsch
* Author URI: https://example.com
* License: GPL v3 or later
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
* Text Domain: wc-composable-product
* Domain Path: /languages
* Requires at least: 6.0
* Requires PHP: 8.3
* WC requires at least: 8.0
* WC tested up to: 10.0
*/
defined('ABSPATH') || exit;
// Define plugin constants
define('WC_COMPOSABLE_PRODUCT_VERSION', '1.1.3');
define('WC_COMPOSABLE_PRODUCT_FILE', __FILE__);
define('WC_COMPOSABLE_PRODUCT_PATH', plugin_dir_path(__FILE__));
define('WC_COMPOSABLE_PRODUCT_URL', plugin_dir_url(__FILE__));
define('WC_COMPOSABLE_PRODUCT_BASENAME', plugin_basename(__FILE__));
// Load Composer autoloader
if (file_exists(WC_COMPOSABLE_PRODUCT_PATH . 'vendor/autoload.php')) {
require_once WC_COMPOSABLE_PRODUCT_PATH . 'vendor/autoload.php';
}
/**
* Check if WooCommerce is active
*/
function wc_composable_product_check_woocommerce() {
if (!class_exists('WooCommerce')) {
add_action('admin_notices', function() {
?>
<div class="notice notice-error">
<p><?php esc_html_e('WooCommerce Composable Products requires WooCommerce to be installed and active.', 'wc-composable-product'); ?></p>
</div>
<?php
});
return false;
}
return true;
}
/**
* Initialize the plugin
*/
function wc_composable_product_init() {
if (!wc_composable_product_check_woocommerce()) {
return;
}
// Load text domain
load_plugin_textdomain('wc-composable-product', false, dirname(WC_COMPOSABLE_PRODUCT_BASENAME) . '/languages');
// Initialize main plugin class
WC_Composable_Product\Plugin::instance();
}
// Use woocommerce_init to ensure all WooCommerce classes including settings are loaded
add_action('woocommerce_init', 'wc_composable_product_init');
/**
* Declare HPOS compatibility
*/
add_action('before_woocommerce_init', function() {
if (class_exists(\Automattic\WooCommerce\Utilities\FeaturesUtil::class)) {
\Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility('custom_order_tables', __FILE__, true);
}
});
/**
* Activation hook
*/
function wc_composable_product_activate() {
if (!class_exists('WooCommerce')) {
deactivate_plugins(WC_COMPOSABLE_PRODUCT_BASENAME);
wp_die(
esc_html__('This plugin requires WooCommerce to be installed and active.', 'wc-composable-product'),
esc_html__('Plugin Activation Error', 'wc-composable-product'),
array('back_link' => true)
);
}
}
register_activation_hook(__FILE__, 'wc_composable_product_activate');