You've already forked wc-composable-product
Implement comprehensive stock management integration (v1.1.0)
Added complete inventory tracking system for composable products: - Stock validation during product selection and add-to-cart - Automatic stock deduction on order completion/processing - Automatic stock restoration on order cancellation/refund - Stock status indicators with visual feedback (In stock, Low stock, Out of stock) - Prevention of out-of-stock item selection - Low stock warnings when 5 or fewer items remain - Order notes documenting all stock changes New files: - includes/Stock_Manager.php: Core stock management logic Modified files: - includes/Cart_Handler.php: Integrated stock validation - includes/Product_Selector.php: Added stock info to product data - includes/Plugin.php: Added Stock_Manager to includes - templates/product-selector.twig: Stock status display - assets/css/frontend.css: Stock indicator styling - languages/*.pot/*.po: 8 new translatable strings Version bumped to 1.1.0 with updated CHANGELOG. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,16 +15,26 @@ defined('ABSPATH') || exit;
|
||||
* Handles adding composable products to cart and calculating prices
|
||||
*/
|
||||
class Cart_Handler {
|
||||
/**
|
||||
* Stock manager instance
|
||||
*
|
||||
* @var Stock_Manager
|
||||
*/
|
||||
private $stock_manager;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->stock_manager = new Stock_Manager();
|
||||
|
||||
add_filter('woocommerce_add_to_cart_validation', [$this, 'validate_add_to_cart'], 10, 3);
|
||||
add_filter('woocommerce_add_cart_item_data', [$this, 'add_cart_item_data'], 10, 2);
|
||||
add_filter('woocommerce_get_cart_item_from_session', [$this, 'get_cart_item_from_session'], 10, 2);
|
||||
add_filter('woocommerce_get_item_data', [$this, 'display_cart_item_data'], 10, 2);
|
||||
add_action('woocommerce_before_calculate_totals', [$this, 'calculate_cart_item_price']);
|
||||
add_action('woocommerce_single_product_summary', [$this, 'render_product_selector'], 25);
|
||||
add_action('woocommerce_checkout_create_order_line_item', [$this->stock_manager, 'store_selected_products_in_order'], 10, 3);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,6 +97,13 @@ class Cart_Handler {
|
||||
}
|
||||
}
|
||||
|
||||
// Validate stock availability
|
||||
$stock_validation = $this->stock_manager->validate_stock_availability($selected_products, $quantity);
|
||||
if ($stock_validation !== true) {
|
||||
wc_add_notice($stock_validation, 'error');
|
||||
return false;
|
||||
}
|
||||
|
||||
return $passed;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user