WooCommerce PDF Invoice Error

User
Fatal error: Uncaught WooCommercePDFInvoiceException: file_get_contents(): Passing null to parameter #2 ($use_include_path) of type bool is deprecated 8192 in /home/storm/sites/hbguq-nimsite-uk/public/wp-content/plugins/woocommerce-pdf-invoice-1/lib/dompdf/src/Helpers.php:507 Stack trace: #0 [internal function]: WooCommercePDFInvoiceHelpers::record_warnings() #1 /home/storm/sites/hbguq-nimsite-uk/public/wp-content/plugins/woocommerce-pdf-invoice-1/lib/dompdf/src/Helpers.php(838): file_get_contents() #2 /home/storm/sites/hbguq-nimsite-uk/public/wp-content/plugins/woocommerce-pdf-invoice-1/lib/dompdf/src/Css/Stylesheet.php(363): WooCommercePDFInvoiceHelpers::getFileContent() #3 /home/storm/sites/hbguq-nimsite-uk/public/wp-content/plugins/woocommerce-pdf-invoice-1/lib/dompdf/src/Dompdf.php(567): WooCommercePDFInvoiceCssStylesheet->load_css_file() #4 /home/storm/sites/hbguq-nimsite-uk/public/wp-content/plugins/woocommerce-pdf-invoice-1/lib/dompdf/src/Dompdf.php(719): WooCommercePDFInvoiceDompdf->processHtml() #5 /home/storm/sites/hbguq-nimsite-uk/public/wp-content/plugins/woocommerce-pdf-invoice-1/classes/class-pdf-send-pdf-class.php(176): WooCommercePDFInvoiceDompdf->render() #6 /home/storm/sites/hbguq-nimsite-uk/public/wp-content/plugins/woocommerce-pdf-invoice-1/classes/class-pdf-export.php(100): WC_send_pdf::get_woocommerce_invoice() #7 /home/storm/sites/hbguq-nimsite-uk/public/wp-includes/class-wp-hook.php(324): WC_pdf_export->handle_shop_order_bulk_actions() #8 /home/storm/sites/hbguq-nimsite-uk/public/wp-includes/plugin.php(205): WP_Hook->apply_filters() #9 /home/storm/sites/hbguq-nimsite-uk/public/wp-admin/edit.php(222): apply_filters() #10 {main} thrown in /home/storm/sites/hbguq-nimsite-uk/public/wp-content/plugins/woocommerce-pdf-invoice-1/lib/dompdf/src/Helpers.php on line 507
Assistant
The error you're seeing is related to the `WooCommerce PDF Invoice` plugin using an outdated method from the `Dompdf` library. The issue is caused by PHP 8.1 or later, which introduces stricter type checking, resulting in a **"Passing null to parameter #2 ($use_include_path) of type bool is deprecated"** warning.

### Root Cause
The `file_get_contents()` function in PHP now expects a boolean for the `$use_include_path` parameter, but it looks like the code is passing `null` instead. This wasn't a problem in previous PHP versions but is deprecated in PHP 8.1 and above.

### Solutions

#### Solution 1: Update the WooCommerce PDF Invoice Plugin
The best approach is to **update the plugin** to its latest version, as the developers may have already fixed this compatibility issue with PHP 8.1+. To do this:
1. Go to **WordPress Admin Dashboard** → **Plugins**.
2. Find **WooCommerce PDF Invoice**.
3. Click **Update Now** if an update is available.

#### Solution 2: Downgrade PHP Version
If updating the plugin is not an option or doesn't resolve the issue, consider downgrading your PHP version to **7.4 or 8.0**, which are more forgiving with type deprecations. You can do this by:
– Changing the PHP version in your hosting control panel.
– Updating your `.htaccess` file if you're on an Apache server:

AddHandler application/x-httpd-php74 .php

#### Solution 3: Manual Code Fix (Temporary Solution)
If neither updating the plugin nor changing the PHP version is feasible, you can manually fix the deprecated parameter in the plugin file.

1. **Open the File:**
– `/home/storm/sites/hbguq-nimsite-uk/public/wp-content/plugins/woocommerce-pdf-invoice-1/lib/dompdf/src/Helpers.php`

2. **Locate Line 507** (or wherever `file_get_contents()` is used):

$content = file_get_contents($filename, null, $context);

3. **Modify It To:**

$content = file_get_contents($filename, false, $context);

This change explicitly sets the `$use_include_path` parameter to `false`, which aligns with the updated function signature in PHP 8.1+.

4. **Save the Changes** and test your WooCommerce PDF invoices again.

### Important Note
The manual code fix is a **temporary solution**. It may be overwritten with future plugin updates, so ensure you have backups or consider using a custom plugin to override this behavior.

#### Solution 4: Contact Plugin Support
If the above solutions don't work, consider reaching out to the **plugin's support team** for an official fix.

Let me know if you need further assistance!

Leave a Comment

Your email address will not be published. Required fields are marked *