diff --git a/.gitignore b/.gitignore index 51e0d31..94976fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Linked sources wp-core wp-plugins +tpp # Editor swap files *.*swp diff --git a/CHANGELOG.md b/CHANGELOG.md index 55b456a..ca82f43 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,25 @@ 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/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.1.3] - 2024-12-31 + +### Added + +- WooCommerce HPOS (High-Performance Order Storage) compatibility declaration +- Prevents duplicate price calculations to avoid conflicts with other pricing plugins + +### Fixed + +- WooCommerce compatibility warnings with Analytics and other WooCommerce extensions +- Price calculation conflicts with third-party pricing plugins + +### Technical + +- Added `before_woocommerce_init` hook to declare HPOS compatibility +- Implemented static flag in `Cart_Handler::calculate_cart_item_price()` to prevent multiple executions +- Added `composable_price_calculated` flag to cart items to prevent re-calculation by other plugins +- Ensures composable products work with WooCommerce's modern order storage system + ## [1.1.2] - 2024-12-31 ### Fixed diff --git a/includes/Cart_Handler.php b/includes/Cart_Handler.php index ad6e974..a62c042 100644 --- a/includes/Cart_Handler.php +++ b/includes/Cart_Handler.php @@ -185,14 +185,25 @@ class Cart_Handler { return; } + // Use static flag to prevent multiple executions + static $already_calculated = false; + if ($already_calculated) { + return; + } + foreach ($cart->get_cart() as $cart_item_key => $cart_item) { if (isset($cart_item['data']) && $cart_item['data']->get_type() === 'composable') { - if (isset($cart_item['composable_products'])) { + if (isset($cart_item['composable_products']) && !isset($cart_item['composable_price_calculated'])) { $product = $cart_item['data']; $price = $product->calculate_composed_price($cart_item['composable_products']); $cart_item['data']->set_price($price); + + // Mark as calculated to prevent re-calculation by other plugins + $cart->cart_contents[$cart_item_key]['composable_price_calculated'] = true; } } } + + $already_calculated = true; } } diff --git a/wc-composable-product.php b/wc-composable-product.php index b643d70..1599c4e 100644 --- a/wc-composable-product.php +++ b/wc-composable-product.php @@ -3,7 +3,7 @@ * 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.2 + * Version: 1.1.3 * Author: Marco Graetsch * Author URI: https://example.com * License: GPL v3 or later @@ -19,7 +19,7 @@ defined('ABSPATH') || exit; // Define plugin constants -define('WC_COMPOSABLE_PRODUCT_VERSION', '1.1.2'); +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__)); @@ -64,6 +64,15 @@ function wc_composable_product_init() { // 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 */