=== PDF InvoiceX - PDF Invoice for WooCommerce ===
Contributors: vishwasr
Tags: woocommerce, pdf, invoice, billing, e-commerce
Requires at least: 6.0
Tested up to: 6.8
Stable tag: 1.0.0
Requires PHP: 7.4
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Generate and download PDF invoices for WooCommerce orders, with customizable settings, email attachments, and bulk generation.

== Description ==

PDF InvoiceX is a lightweight plugin that enables store owners to generate professional PDF invoices for paid WooCommerce orders. With an intuitive settings interface, customizable templates, and seamless integration with WooCommerce, this plugin enhances your store’s billing process.

### Key Features
- **Automatic PDF Generation**: Create PDF invoices for paid orders with a single click.
- **Admin & Frontend Downloads**: Download invoices from the admin orders page or customer’s My Account area.
- **Email Attachments**: Attach PDF invoices to selected WooCommerce emails (e.g., Completed Order).
- **Bulk PDF Generation**: Generate ZIP files containing multiple invoices from the admin orders list.
- **Customizable Settings**:
  - Upload a store logo (recommended: 200x100px).
  - Set store address, invoice number prefix/suffix, and footer text.
  - Choose invoice templates.
  - Select which emails include PDF attachments.
- **Sequential Invoice Numbers**: Automatically assign unique invoice numbers with customizable prefixes (e.g., INV-) and suffixes.
- **Secure & Extensible**: Built with WordPress security standards, including nonces, sanitization, and capability checks.
- **WooCommerce Integration**: Matches WooCommerce’s design and workflow, ensuring a seamless user experience.

Perfect for store owners who need professional invoicing without complexity. The plugin uses mPDF for reliable PDF generation and is optimized for performance and compatibility.

== Installation ==

1. **Upload the Plugin**:
   - Download the plugin ZIP file.
   - In your WordPress admin, go to Plugins > Add New > Upload Plugin.
   - Upload the ZIP file and click "Install Now."
2. **Activate the Plugin**:
   - After installation, click "Activate Plugin."
3. **Install Dependencies**:
   - mPDF is already included in the plugin.
   - Run `composer install` in the plugin directory (`wp-content/plugins/pdf-invoicex`) to install `vendor/autoload.php`.
   - Alternatively, manually download mPDF and place it in the plugin’s `vendor` folder.
4. **Configure Settings**:
   - Go to WooCommerce > PDF InvoiceX in the admin menu.
   - Set up General (logo, address, invoice numbers), Template, and Email settings.
   - Save changes to start generating invoices.
5. **Verify Permissions**:
   - Ensure `wp-content/uploads/pdf-invoicex-invoices/` and your system’s temporary directory (e.g., `/tmp/`) are writable.

**Note**: Requires WooCommerce 3.5 or higher. PHP 7.4+ is recommended for mPDF compatibility.

== Frequently Asked Questions ==

= Why am I seeing "Failed to generate PDF"? =
This error may occur if:
- mPDF is not installed. Run `composer install` in the plugin directory.
- The `wp-content/uploads/pdf-invoicex-invoices/` directory or system temp directory is not writable. Check server permissions (e.g., `chmod 775`).
- The template file (`templates/default.php`) is missing or corrupted. Ensure it exists in the plugin’s `templates` folder.
Enable `WP_DEBUG` in `wp-config.php` and check `wp-content/debug.log` for detailed errors.

= How do I customize the invoice template? =
The default template is in `templates/default.php`. To create a custom template:
1. Copy `default.php` to your theme’s `pdf-invoicex` folder (e.g., `wp-content/themes/your-theme/pdf-invoicex/custom.php`).
2. Modify the HTML/CSS as needed.
3. Use the `pdfinvx_templates` filter to register your template:
```php
add_filter('pdfinvx_templates', function($templates) {
    $templates['custom'] = [
        'name' => __('Custom Template', 'pdf-invoicex'),
        'image' => get_theme_file_uri('/pdf-invoicex/custom.jpg'), // Path to preview image
        'description' => __('A custom invoice template tailored for your brand.', 'pdf-invoicex')
    ];
    return $templates;
});
```
4. Select your template in WooCommerce > PDF Invoice > Template.

= Can I attach invoices to specific emails? =
Yes! In WooCommerce > PDF Invoice > Emails, select which WooCommerce emails (e.g., “Completed Order”) should include the PDF invoice as an attachment.

= Why is the logo upload not working? =
Ensure the WordPress media library is enabled. If you see “Media library failed to load,” check:
- JavaScript errors in the browser console (DevTools).
- WordPress permissions for media uploads.
- Plugin conflicts with other media-related plugins.

= How do I generate invoices in bulk? =
In the WooCommerce > Orders list:
1. Select multiple paid orders.
2. Choose “Generate PDF Invoices” from the Bulk Actions dropdown.
3. Click “Apply” to download a ZIP file containing all invoices.


== Screenshots ==

1. **Settings Page**: General Tab to configure logo & address.
2. **Settings Page**: Template Tab to select PDF template.
3. **Settings Page**: Emails Tab to select which WooCommerce emails should PDF Invoice be included.
4. **Order Details Meta Box**: Access invoices from the order edit page.
5. **Admin Orders Page**: Download PDF invoices in bulk directly from the orders list.
6. **Frontend My Account**: Customers can download invoices from their order history.
7. **Frontend Individual Order**: Customers can download invoices from individual orders.

== Changelog ==

= 1.0.0 =
* Initial release with PDF generation, admin/frontend downloads, email attachments, bulk generation, and customizable settings.


== License ==

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