=== PDF InvoiceX ===
Contributors: vishwasr
Tags: woocommerce, pdf, invoice, billing, packing slip
Requires at least: 6.0
Tested up to: 7.0
Stable tag: 2.0.0
Requires PHP: 7.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

WooCommerce PDF invoice plugin — auto-generate invoices, credit notes & packing slips. Email attachments, bulk download, VAT/GST support. Free.

== Description ==

**PDF InvoiceX** is a free WooCommerce PDF invoice plugin that automates your entire billing workflow. Generate, send, and manage PDF invoices, credit notes, and packing slips — all from within WooCommerce, with no monthly fees.

Whether you run a small shop or a high-volume store, PDF InvoiceX handles invoice numbering, VAT/GST compliance, bulk exports, and customer-facing downloads out of the box.

---

### 📄 PDF Invoices

- **Auto-generate** invoices when orders reach any configured status (e.g. Processing, Completed).
- **Sequential invoice numbering** with prefix, suffix, and optional yearly counter reset (e.g. 2025-000001).
- **Download or view** invoices from the WooCommerce admin, My Account page, and the Thank You / order-received page.
- **Inline PDF preview** — opens in a new tab without leaving the page.
- **Regenerate** any invoice on demand, bypassing the cache.
- **Send Invoice to Customer** directly from the order edit screen — no duplicate email sends.

### 📋 Credit Notes

- Auto-generated when an order is refunded (configurable in Advanced settings).
- Per-refund breakdown: items refunded, quantities, refund reasons, and totals.
- Available for download from the order edit screen.

### 📦 Packing Slips

- Pricing-free shipping document for warehouse use — shows product name, SKU, variant options, and quantity.
- Ship-from and ship-to address blocks included.
- Enable via Advanced settings; appears on order edit screen and customer My Account.

### 🎨 Invoice Templates

- **4 built-in templates**: Default, Modern, Classic, Colorful.
- **Live preview** in the settings panel before applying.
- **Override-safe**: template variables are injected at render time — no class coupling, easy to extend with custom templates via the `pdfinvx_templates` filter.

### 📧 Email Attachments

- Attach PDF invoices to any WooCommerce transactional email — fully configurable per email type.
- Dedicated **Send Invoice to Customer** button on the order edit screen.

### ⚡ Bulk Invoice Generation

- Select multiple orders → *Generate PDF Invoices* → download as a ZIP.
- **Background processing via Action Scheduler** — handles large order volumes without PHP timeouts.
- Synchronous fallback for sites without Action Scheduler.

### 🧾 VAT / GST & Compliance

- Display your **store VAT or GST registration number** on every invoice.
- Optional **customer VAT / GST field** at checkout, stored to order meta and printed on the invoice.
- **Paper size** selector: A4, Letter, or Legal.
- **WooCommerce HPOS** (High-Performance Order Storage) compatible.
- **Fully translatable** — includes a complete `.pot` file with 100+ strings.

---

### Why PDF InvoiceX?

Most WooCommerce invoice plugins charge $49–$99/year for features like credit notes, packing slips, VAT fields, or bulk exports. PDF InvoiceX provides all of these for free, with clean code that follows WordPress and WooCommerce coding standards.

- ✅ No subscription or licence fee
- ✅ HPOS compatible
- ✅ Works with WooCommerce Subscriptions
- ✅ Action Scheduler integration for large stores
- ✅ Plugin Check (PCP) compliant

---

== Installation ==

1. Upload the plugin ZIP via **Plugins > Add New > Upload Plugin**.
2. Click **Activate Plugin**.
3. Navigate to **WooCommerce > PDF InvoiceX** to configure General, Template, Email, and Advanced settings.
4. Ensure `wp-content/uploads/pdf-invoicex/` is writable by the web server.

**Requires**: WooCommerce 6.0+, PHP 7.4+.

== Frequently Asked Questions ==

= Why am I seeing "Failed to generate PDF"? =
Check the following:
- The `wp-content/uploads/pdf-invoicex/` directory must be writable by the web server.
- PHP memory limit should be at least 128 MB (mPDF recommendation).
- Enable `WP_DEBUG` and check `wp-content/debug.log` for a detailed error message.

= How do I create a custom invoice template? =
Copy any built-in template from the plugin's `templates/` folder to your theme folder, then register it:

```php
add_filter( 'pdfinvx_templates', function( $templates ) {
    $templates['my-template'] = array(
        'name'        => __( 'My Template', 'pdf-invoicex' ),
        'image'       => get_theme_file_uri( 'pdf-invoicex/my-template.jpg' ),
        'description' => __( 'Custom invoice template.', 'pdf-invoicex' ),
    );
    return $templates;
} );
```

Then select it under **WooCommerce > PDF InvoiceX > Template**.

= Can I attach invoices to specific WooCommerce emails? =
Yes. Go to **WooCommerce > PDF InvoiceX > Emails** and tick the emails you want the PDF attached to (e.g. Completed Order, Processing Order).

= Does it support HPOS (High-Performance Order Storage)? =
Yes. The plugin is fully compatible with WooCommerce HPOS (custom order tables).

= Does it work with WooCommerce Subscriptions? =
Yes. Invoices are automatically generated for subscription renewal orders.

= How do I generate invoices in bulk? =
In **WooCommerce > Orders**, select the orders, choose **Generate PDF Invoices** from the Bulk Actions dropdown, and click Apply. A ZIP file will be downloaded (or queued in the background for large batches).

= How do I reset the invoice counter? =
Go to **WooCommerce > PDF InvoiceX > Advanced**, scroll to **Invoice Numbering**, enter the value in **Reset Counter To**, and click **Apply Reset**.

== Screenshots ==

1. **General Settings** — Upload your logo, set store address, and configure invoice number prefix/suffix.
2. **Template Selection** — Choose from four built-in templates with a live preview modal.
3. **Email Settings** — Select which WooCommerce emails should include the PDF invoice attachment.
4. **Advanced Settings** — Configure VAT/GST, paper size, automation triggers, credit notes, and packing slips.
5. **Order Edit Screen** — Download, view, send, or regenerate the invoice; download credit note and packing slip.
6. **Orders List** — Invoice status column with invoice number; bulk generate PDF invoices.
7. **My Account** — Customers can download or view their invoice, and download the packing slip.
8. **Thank You Page** — Download or view invoice immediately after checkout.

== Changelog ==

= 2.0.0 =
* New: Credit note document type — auto-generated on refund, with per-refund item breakdown.
* New: Packing slip document type — warehouse-friendly, no pricing, with ship-from/to address blocks.
* New: Advanced settings tab — VAT/GST number, paper size (A4/Letter/Legal), document type toggles, automation triggers, and yearly counter reset.
* New: Store VAT / GST registration number displayed on all invoices.
* New: Optional customer VAT / GST field at WooCommerce checkout.
* New: Automatic invoice generation on configurable order status change.
* New: "Send Invoice to Customer" button on order edit screen (prevents duplicate sends).
* New: "Regenerate Invoice" button on order edit screen (bypasses cache).
* New: Invoice status column on orders list — shows invoice number or a generate shortcut (classic WP_Query + HPOS).
* New: Inline PDF viewer — "View Invoice" opens in a new tab from admin, My Account, and Thank You page.
* New: Thank You / order-received page shows Download and View Invoice buttons.
* New: Packing slip and credit note download buttons on My Account order detail.
* New: Background bulk generation via Action Scheduler — no PHP timeouts on large stores.
* New: Synchronous ZIP fallback when Action Scheduler is unavailable.
* New: File-based PDF cache in `uploads/pdf-invoicex/` with cache invalidation on order update.
* New: WooCommerce Subscriptions support — invoice generated for renewal orders.
* New: Yearly invoice counter reset with year-prefixed numbering (e.g. 2025-000001).
* New: One-time next-invoice-number override (clears after first use).
* New: Complete `.pot` translation catalog (100+ strings).
* Fix: Double email attachment caused by duplicate hook registration.
* Fix: Multi-item orders clipped at page break — mPDF autoPageBreak now enabled.
* Fix: Templates coupled to class via `$this->` — now use injected variables, safe to override.
* Fix: Temporary PDF files leaked after email attachment.
* Fix: `getimagesize()` fatal on remote logo URLs — replaced with HTML onerror fallback.
* Fix: Invoice date used current time instead of actual payment/completion date.
* Fix: Generic `order_id` query variable conflicted with other plugins — renamed to `pdfinvx_order_id`.

= 1.0.0 =
* Initial release: PDF invoice generation, admin and frontend downloads, email attachments, bulk ZIP, and template settings.

== License ==

This plugin is licensed under the GPLv2 or later. See the `LICENSE` file for details.