=== Materials Stock for Makers ===
Contributors: starlink1207
Tags: woocommerce, inventory, bill of materials, raw materials, stock
Requires at least: 6.5
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.3
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Raw material inventory and bills of materials for handmade WooCommerce shops. Deducts materials on orders and shows how many you can make.

== Description ==

WooCommerce tracks stock for finished products only. If you make what you sell — candles, soap, jewellery, cosmetics, food — you also need to know how much wax, oil, beads or flour you have left. Materials Stock for Makers adds a raw material inventory to WooCommerce and connects it to your products with a simple bill of materials (BOM).

**Why makers choose it**

* The full bill of materials and automatic deduction are in the free version, with no product limits and no ads.
* Every deduction is atomic, cancelled and refunded orders restore exactly what was taken, and a full stock history records the reason for every change.
* It runs inside WooCommerce on your own site, with no monthly SaaS fee.

**Materials**

* Add materials with a name, any unit you like (g, kg, ml, L, pcs, m…), current stock and an optional cost per unit.
* Manage them under WooCommerce > Materials: search, sort, edit, delete and bulk delete.
* Adjust stock manually (add, remove or set to a counted amount) with a reason. Every change is recorded in the stock history with date, user and related order.
* Type quantities and costs the way you write them: "0,5" and "0.5" both work, as do "1.234,5" and "1,234.5".

**Bill of materials per product**

* On the product edit screen, list the materials and quantities needed to make one unit of a simple product.
* See instantly how many units you can make from current material stock.

**Automatic deduction on orders**

* When WooCommerce reduces stock for an order, the materials are deducted (quantity per unit × ordered quantity).
* When an order is cancelled or refunded, the materials are restored. Partial refunds with restocking restore the matching amount.
* Each order is deducted only once, and every change is atomic so simultaneous orders never miscount.
* Materials used are added as an order note.

**No overselling of shared materials**

* Products that share a material (the same wax in a candle and a tealight) are added together across the whole cart and compared with that material's stock — when adding to the cart, changing quantities and at checkout, in both the classic and the block cart and checkout.
* Choose what happens when materials run short: Allow (sell anyway), Warn (a notice in the cart) or Block (an error naming the material and the most that can be ordered).

**Production runs**

* Made a batch of 20? Record a production run from the product's bill of materials box or the Materials screen: materials for all units are deducted in one all-or-nothing step, the product stock goes up by 20 and the run is written to the stock history as "Production run".
* Mark products you make in batches as "Made ahead" so orders do not deduct their materials a second time.

**Makeable quantity**

* Optionally, per product, set the WooCommerce stock quantity to the number of units that can be made: the lowest of (material stock ÷ quantity needed). It updates automatically whenever material stock changes.

**Warnings**

* Materials at or below zero are highlighted in the list, counted on the menu and flagged in the product's bill of materials.
* The plugin shows its warnings only on its own screens — no dashboard banners.

Compatible with WooCommerce High-Performance Order Storage (HPOS) and the cart and checkout blocks. Nothing is loaded on your shop's regular pages.

A Pro version adds bills of materials for each product variation, automatic material cost per product with a margin column in the products list, receiving deliveries with their purchase cost (weighted average unit cost), an inventory value card with the value on any past date, per-order packaging materials included in costs and margins, a Production tab listing every run with its material cost, low-stock thresholds with a daily email alert, and CSV import and export of materials and stock history.

== Installation ==

1. Install and activate WooCommerce.
2. Upload the plugin folder to `/wp-content/plugins/` or install it from the Plugins screen, then activate it.
3. Go to WooCommerce > Materials and add your materials.
4. Edit a simple product and fill in the "Materials (bill of materials)" box.

== Frequently Asked Questions ==

= When are materials deducted? =

At the same moment WooCommerce reduces product stock for an order — usually when payment is received or the order is set to processing or completed.

= What happens if a material goes below zero? =

By default (Allow) orders are never blocked; the material is shown as out of stock so you know to restock. If you enable "makeable quantity" for a product, its stock becomes 0 and WooCommerce stops selling it.

= Can it stop customers ordering more than my materials allow? =

Yes. Under WooCommerce > Materials > Settings, set "When materials run short" to Block. The whole cart is checked, so two products that share a material cannot together use more than you have. Warn lets the order through and shows a notice in the cart instead. Sites updated from an earlier version keep Allow until you change it.

= How do production runs work with orders? =

Record a run when you make a batch: materials are deducted and the units are added to the product stock. Tick "Made ahead" on that product (the production form does it for you) and its orders will not deduct materials again. Products without "Made ahead" keep the usual behaviour: materials are deducted when they are ordered.

= Can I type decimals with a comma? =

Yes. Every quantity and cost field accepts "0,5" as well as "0.5".

= Can I turn off the automatic deduction? =

Yes, under WooCommerce > Materials > Settings.

= Does it work with variable products? =

The free version supports simple products. Bills of materials per variation are part of the Pro version.

= What is removed when I delete the plugin? =

All materials, bills of materials, stock history, production runs and plugin settings.

== Screenshots ==

1. Materials list with stock, unit, cost and the products that use each material.
2. Bill of materials on the product screen, with the number of units you can make from current stock.
3. Stock history: every deduction, restore and manual adjustment with its reason and order.
4. Record production: deduct the materials of a whole batch and add the units to stock.
5. Settings: what to do when the cart needs more of a shared material than you have.

== Changelog ==

= 1.0.3 =
* New: whole-cart check for shared materials when adding to the cart, updating it and at checkout (classic and blocks), with Allow / Warn / Block. Existing sites keep Allow.
* New: production runs ("Make N") from the product screen and the Materials screen, logged as "Production run".
* New: "Made ahead" product option so orders do not deduct materials already used in production.
* Improved: thousands separators are understood in quantity and cost fields ("1.234,5", "1,234.5").
* Improved: no dashboard banners; plugin messages appear only on its own screens.
* Improved: fewer database queries on every page load.
* Pro: receive stock with purchase cost (weighted average), inventory value and value on date, per-order packaging, Production tab.

= 1.0.2 =
* Hardened output escaping, input sanitizing and database queries.
* 14-day free trial of Pro from the plugin screen.

= 1.0.1 =
* Removed the product limit from the free version.
* Cleaner admin menu (no separate Contact Us item).

= 1.0.0 =
* First release.
