Dynamic FIFO Margin/VAT Stock Split in WooCommerce
Who can help me or guide me in the right direction?
We are launching a completely new WooCommerce website (clean installation). We sell collectibles that fall under two different tax structures: some are under the Dutch/EU Margin Scheme (0% VAT applied to the total retail price) and others fall under the standard VAT rate (21% VAT).
We want to sell these from one single product page (supporting both simple products and variable products, e.g., with color variations). The system must automatically switch the tax class in the cart based on a First-In-First-Out (FIFO) logic as soon as the Margin stock runs out and the VAT stock is used.
Desired Backend Functionality (WP-Admin)
- Within every WooCommerce product and product variation, we need two separate, custom stock fields:
marge_stock_quantity(Linked to Tax Class: Margin / 0% VAT)btw_stock_quantity(Linked to Tax Class: Standard / 21% VAT)
- The total stock displayed on the frontend must automatically be the sum of these two fields ($marge\_stock + btw\_stock$).
- The store administrator must be able to audit and manage the stock level per unit (margin or VAT) independently.
2. Desired Frontend & Cart/Checkout Logic
- Frontend: The customer sees a single product with the total combined stock (e.g., "15 items in stock"). The retail price is exactly the same for both stock units (e.g., €19.99 including any applicable VAT).
- Cart Logic (FIFO Priority): When adding to the cart, the system must check the available stock types using a cart hook.
- Priority 1 (Margin): As long as
marge_stock_quantity> 0, the product in the cart receives the Tax Class "Margin / 0% VAT". - Priority 2 (VAT): As soon as
marge_stock_quantityreaches 0, the system must switch any remaining or subsequent quantities to the Tax Class "Standard / 21% VAT".
- Priority 1 (Margin): As long as
Crucial Requirement: Cart Item Splitting
If a customer orders a quantity that exceeds the remaining margin stock (e.g., the customer orders 5 items, but there are only 3 items left in margin stock):
- The system must programmatically split this into two separate cart items behind the scenes (3 items with the Margin tax class, and 2 items with the Standard 21% VAT tax class).
- This splitting is strictly necessary so WooCommerce can calculate the VAT totals legally and technically correct in the checkout, on the order confirmation, and on the PDF invoice. No manual adjustments should be required afterwards.
How can we do this? Is it even possible or do we need to outsource this?