=== Batch Expiry Stock ===
Contributors: batchexpirystock
Tags: lot number, expiry date, batch tracking, fefo, inventory
Requires at least: 6.5
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Lot numbers and expiry dates for WooCommerce stock. Ships the earliest-expiring lot first (FEFO) and finds recalled lots in seconds.

== Description ==

Batch Expiry Stock is made for small WooCommerce shops that sell food, cosmetics, supplements, pet food or anything else with a lot (batch) number and a best-before date.

Record each delivery as a lot, and every order automatically takes units from the lot that expires first. You always know which lot went to which customer.

**Goods received**

* Add lots (lot number, expiry date, quantity, received date, note) from the product edit screen or from **WooCommerce > Batches**.
* Optional stock sync: the product stock quantity always equals the total of its lots.

**First-expired, first-out (FEFO) deduction**

* When WooCommerce reduces stock for an order, units are taken from the earliest-expiring lots first.
* The lots and quantities used are saved on each order line.
* An order is never deducted twice. Cancelled orders and restocked refunds go back to the exact lots they came from.
* Expired lots can be skipped automatically.
* Quantity updates are atomic, so two simultaneous orders cannot take the same units.

**Lots on orders and packing slips**

* Lot numbers and expiry dates appear on the admin order screen, in order emails and in My Account (customer display can be turned off).
* A printable packing slip lists every line with its lots and expiry dates.
* Works with packing slip plugins that print order item meta.

**Expiry overview**

* The "Expiring" tab lists lots that are already expired or expire within N days (30 by default).
* A dashboard widget shows the counts and the next lots to expire.

**Recall lookup**

* Search a lot number to see every order, customer, email, phone and quantity that received it.

All dates use your site's time zone. Works with High-Performance Order Storage (HPOS) and the block checkout. Lots are stored in their own database table.

Pro adds lots for each variation of variable products, a once-a-day email of expired and expiring lots, CSV import of goods received plus lot and recall CSV exports, a "Best before" date on product pages taken from the next lot to ship, and automatic removal of expired lots from stock with a disposal log.

== Installation ==

1. Install and activate WooCommerce.
2. Upload the `batch-expiry-stock` folder to `/wp-content/plugins/` or install the plugin from the Plugins screen, then activate it.
3. Go to **WooCommerce > Batches > Settings** and choose whether product stock should follow the lot totals.
4. Add lots from a product's "Lots & expiry dates" box or from **WooCommerce > Batches**.
5. Make sure "Manage stock?" is enabled for the product (stock sync turns it on for you).

== Frequently Asked Questions ==

= When are units taken from a lot? =

At the moment WooCommerce reduces the order's stock (normally when the order becomes Processing or On hold). The plugin follows exactly the quantity WooCommerce took.

= What happens when there is not enough lot stock? =

The available lots are used first. The rest is marked "No lot" on the order line and an order note explains it, so you can fix it before shipping.

= What happens on a cancellation or a refund? =

When WooCommerce puts stock back (cancelled order or a refund with "Restock refunded items"), the units return to the same lots they were taken from.

= Which products are supported? =

Simple products. Variable products are supported in Pro.

= Are expired lots sold? =

Not when "Skip expired lots" is on (the default). Expired lots are listed on the Expiring tab so you can deal with them.

= Can I hide lot numbers from customers? =

Yes. Turn off "Show lots to customers" in the settings. Staff still see lots in the admin and on the packing slip.

= What is removed when I delete the plugin? =

The plugin's settings, its database tables and the lot data stored on order lines.

== Screenshots ==

1. Batches screen with the goods-received form and the lot list.
2. Lots & expiry dates box on the product edit screen.
3. Expiring tab with expired and expiring lots.
4. Recall lookup showing the orders and customers that received a lot.
5. Lots on the order screen and the printable packing slip.

== Changelog ==

= 1.0.0 =
* First release: lots with expiry dates, FEFO deduction, restore on cancel and refund, order and packing slip display, expiring list and dashboard widget, recall lookup.
