# CartSplitter - Partial Checkout for WooCommerce

**Contributors:** rebelliousdigital  
**Tags:** woocommerce, cart splitter, partial checkout, cart, checkout, save for later  
**Requires at least:** 6.0  
**Tested up to:** 6.9  
**Stable tag:** 1.0.0  
**Requires PHP:** 7.4  
**License:** GPL-2.0-or-later  
**License URI:** https://www.gnu.org/licenses/gpl-2.0.html  

---

## Why use CartSplitter?

Standard WooCommerce checkout assumes the **whole cart** goes to payment. That hurts stores when shoppers want to:

- Pay for **part** of the cart now (budget, payday timing, trial purchases).
- **Split** urgent vs. later items without manually removing products and losing track.
- Avoid **abandoning** a large cart because the total feels too high today.

**CartSplitter** adds an **opt-out checkbox on every cart line** (all lines stay selected by default). Customers uncheck what they are not buying this time; those lines remain in the cart with clear **saved-for-later** treatment. **Subtotal, shipping, taxes, and coupons** apply only to **selected** lines, so checkout matches intent. After the order, **remaining lines stay in the cart** for the next purchase.

**Merchant outcomes:** fewer all-or-nothing abandonments, totals that match what customers actually buy, and clearer admin visibility when an order was a **partial** checkout.

---

## Features

**Shopping experience**

- Checkbox per cart item (opt-out model; everything selected by default)
- Optional **Select all / Deselect all**
- Cart notice when fewer than all items are selected
- Deselected rows visually distinct (“saved for later”)

**Correct commerce logic**

- Unselected items **stay in the cart**; quantities are restored after totals run
- Shipping and **coupons** recalculate for the **selected** subset only
- Order contains only selected lines; partial orders can show a **Partial** badge in admin

**Compatibility**

- **Shortcode** cart & checkout and **Cart / Checkout blocks** (Store API)
- **HPOS** (High-Performance Order Storage)
- After checkout, remaining items are ready for the next session

**Configuration**

- Tab under **WooCommerce → Settings → CartSplitter** (enable, notice, checkbox position, select-all toggle)

Optional **CartSplitter Pro** (licensed separately) adds branding, minimum amounts, role rules, remainder emails, recovery links, and stats—see [Rebellious Digital Plugins](https://plugins.rebelliousdigital.co.uk).

---

## Requirements

| Requirement | Minimum |
|-------------|---------|
| WordPress | 6.0 |
| WooCommerce | 7.0 |
| PHP | 7.4 |

---

## External services (Pro licensing only)

If you activate **CartSplitter Pro**, license operations use [SureCart](https://surecart.com) at **`https://api.surecart.com`** when an administrator activates or validates a license—not during storefront cart or checkout traffic.

- Privacy: https://surecart.com/privacy-policy/
- Terms: https://surecart.com/terms-and-conditions/

The free plugin does not require this connection for cart or checkout behaviour.

---

## Installation

1. Upload the plugin folder to `/wp-content/plugins/` or install from WordPress.org.
2. Activate under **Plugins**.
3. Open **WooCommerce → Settings → CartSplitter**.

---

## How it works (customer view)

1. Customer adds items to the cart (all lines selected).
2. On the cart page, they **uncheck** lines they are not buying today.
3. Totals update so only selected lines count toward subtotal, shipping, and discounts.
4. At checkout, the order matches that selection.
5. Unchecked lines **remain in the cart** after the order for a future purchase.

---

## How it works (technical overview)

Selection is stored in session (classic AJAX + REST for blocks). During total calculation, unselected lines are temporarily zeroed so WooCommerce’s core pricing, shipping, and coupon logic runs against the **selected** subset only; quantities are then restored so the cart contents stay intact. At checkout, the order is built from selected lines; remaining cart lines are preserved.

---

## REST API (blocks)

| Endpoint | Method | Purpose |
|----------|--------|---------|
| `/wp-json/cspc-partial/v1/selection` | GET | Current selection |
| `/wp-json/cspc-partial/v1/selection` | POST | Toggle one line |
| `/wp-json/cspc-partial/v1/selection/bulk` | POST | Replace selection |

---

## Settings

**WooCommerce → Settings → CartSplitter**

| Setting | Default | Description |
|---------|---------|-------------|
| Enable CartSplitter | On | Master switch |
| Show “Select all” toggle | On | Bulk select/deselect |
| Show partial checkout notice | On | Banner when selection is partial |
| Checkbox position | Before product name | Placement in the cart row |

---

## Hooks & filters

```php
add_filter( 'cspc_partial_notice_text', function ( $text, $selected, $total ) {
    return sprintf( 'Buying %d of %d items today.', $selected, $total );
}, 10, 3 );

add_filter( 'cspc_settings', function ( $settings ) {
    return $settings;
} );
```

---

## FAQ

**Will this conflict with other cart plugins?**  
CartSplitter uses standard `woocommerce_before_calculate_totals` / `woocommerce_after_calculate_totals` hooks and restores quantities instead of deleting rows. Third-party plugins that heavily customize the same hooks may need priority testing.

**Subscriptions or bundles?**  
The UI works for cart line items generally; complex product-type plugins may need extra validation on your stack.

**Coupons on unselected lines?**  
During the calculation pass, unselected quantities are zeroed so coupon evaluation sees only selected lines.

**Theming**  
Styles use CSS custom properties, e.g. `--cspc-primary`, so themes can override colours.

---

## Changelog

### 1.0.0

- Initial release under the CartSplitter brand (`cspc` prefix, text domain `cartsplitter-partial-checkout-for-woocommerce`).
