To change the invoice due date based on different customer roles in WooCommerce PDF Invoices & Packing Slips, you can use custom code snippets. The plugin allows for customization via hooks and filters.
Method 1: Using a Custom Function (PHP Snippet)
You can add a custom function to your theme’s functions.php file or a custom plugin to modify the due date dynamically based on user roles.
Example Code:
/**
* Change invoice due date based on customer role.
*/
add_filter( 'wpo_wcpdf_invoice_title', 'custom_invoice_due_date_by_role', 10, 2 );
function custom_invoice_due_date_by_role( $title, $document ) {
if ( ! is_object( $document ) || ! isset( $document->order ) ) {
return $title;
}
$order = $document->order;
$user_id = $order->get_user_id();
if ( $user_id ) {
$user = get_user_by( 'id', $user_id );
$due_date = '';
// Set due dates based on user role
if ( in_array( 'wholesale_customer', $user->roles ) ) {
$due_date = 'Net 30'; // Wholesale customers get 30 days
} elseif ( in_array( 'subscriber', $user->roles ) ) {
$due_date = 'Due on Receipt'; // Subscribers pay immediately
} else {
$due_date = 'Net 15'; // Default due date for other roles
}
// Append due date to the invoice title
$title .= ' - ' . $due_date;
}
return $title;
}
Explanation:
- This code checks the user role associated with the order.
- Depending on the role (
wholesale_customer,subscriber, etc.), it sets a different due date. - The due date is appended to the invoice title.
Method 2: Using a Plugin Extension (Advanced)
If you need more complex due date rules (e.g., dynamic dates based on order date), you can extend the plugin further:
/**
* Set dynamic due date (e.g., 15 days from order date for wholesale customers).
*/
add_filter( 'wpo_wcpdf_after_order_data', 'custom_dynamic_due_date', 10, 2 );
function custom_dynamic_due_date( $document_type, $order ) {
$user_id = $order->get_user_id();
if ( $user_id ) {
$user = get_user_by( 'id', $user_id );
if ( in_array( 'wholesale_customer', $user->roles ) ) {
$order_date = $order->get_date_created();
$due_date = $order_date->modify( '+15 days' )->format( 'Y-m-d' );
echo '<p><strong>Due Date:</strong> ' . $due_date . '</p>';
}
}
}
Where to Add the Code?
- Option 1: Add to your child theme’s
functions.php. - Option 2: Use a code snippets plugin (like “Code Snippets”).
- Option 3: Create a custom plugin.
Testing
- Place a test order with different user roles.
- Check the PDF invoice to ensure the due date changes correctly.
The WooCommerce PDF Invoices & Packing Slips plugin by WP Overnight does not have a built-in function specifically for adjusting due dates based on customer roles. However, it does provide hooks and filters that allow you to customize invoice details, including dates.
Available Date-Related Features in the Plugin
- Invoice Date Format
- You can modify the invoice date format via:
- WooCommerce → PDF Invoices → Documents → Invoice → Date Format
- Or via code using
wpo_wcpdf_date_formatfilter.
add_filter( 'wpo_wcpdf_date_format', 'custom_invoice_date_format' );
function custom_invoice_date_format( $format ) {
return 'F j, Y'; // Changes to "June 26, 2025"
}
- Custom Due Date Field
- You can manually add a due date field in the invoice template by:
- Editing the template file (
invoice.phpinwp-content/uploads/wpo_wcpdf/templates/). - Using a filter to dynamically set it.
- Editing the template file (
add_action( 'wpo_wcpdf_after_order_data', 'add_custom_due_date', 10, 2 );
function add_custom_due_date( $document_type, $order ) {
if ( $document_type == 'invoice' ) {
echo '<p><strong>Due Date:</strong> ' . date_i18n( 'F j, Y', strtotime( '+15 days' ) ) . '</p>';
}
}
- Dynamic Due Date Based on Order Date
- You can calculate a due date relative to the order date:
add_action( 'wpo_wcpdf_after_order_data', 'add_dynamic_due_date', 10, 2 );
function add_dynamic_due_date( $document_type, $order ) {
if ( $document_type == 'invoice' ) {
$order_date = $order->get_date_created();
$due_date = $order_date->modify( '+30 days' )->format( 'Y-m-d' );
echo '<p><strong>Due Date:</strong> ' . $due_date . '</p>';
}
}
No Built-In Role-Based Due Date Adjustment
- The plugin does not natively support setting different due dates per customer role.
- You must use custom PHP code (like in my previous examples) to achieve this.
Alternative Solutions
- Use a Plugin Extension
- PDF Invoices & Packing Slips Professional (Premium version) offers more customization options.
- Third-party plugins (like WooCommerce Conditional Content) can help show different due dates based on rules.
- Custom Invoice Template
- Override the default template and add role-based logic directly in
invoice.php.
Conclusion
If you need automatic due date adjustments by customer role, you must use custom code (PHP snippets). The plugin itself does not have a built-in feature for this.
Would you like help refining a snippet for your specific needs? 🚀
Example
Here’s a clean and effective PHP snippet to add a 30-day due date for the wholesalecredit customer role in WooCommerce PDF Invoices & Packing Slips:
Solution: Dynamic Due Date for ‘wholesalecredit’ Role
Add this to your child theme’s functions.php or a custom plugin:
/**
* Add a 30-day due date for 'wholesalecredit' customers in PDF invoices.
*/
add_action( 'wpo_wcpdf_after_order_data', 'add_wholesalecredit_due_date', 10, 2 );
function add_wholesalecredit_due_date( $document_type, $order ) {
// Only apply to invoices
if ( $document_type !== 'invoice' ) return;
// Get user and check role
$user_id = $order->get_user_id();
if ( ! $user_id ) return; // Guest orders
$user = get_user_by( 'id', $user_id );
if ( ! in_array( 'wholesalecredit', $user->roles ) ) return; // Only for 'wholesalecredit' role
// Calculate due date (order date + 30 days)
$order_date = $order->get_date_created();
$due_date = $order_date->modify( '+30 days' )->format( get_option( 'date_format' ) );
// Display due date under order details
echo '<div class="due-date"><strong>Due Date:</strong> ' . $due_date . '</div>';
}
Key Features:
- Role-Specific Logic
- Only applies to users with the
wholesalecreditrole. - Skips guest orders and other roles.
- Dynamic Date Calculation
- Takes the order date and adds 30 days using PHP’s
DateTime.
- Proper Date Formatting
- Uses WordPress’s default date format (from
Settings → General).
- Clean Output in Invoice
- Appears under the order data section with clear labeling (
Due Date: [date]).
Alternative: Append Due Date to Invoice Title
If you prefer the due date in the invoice title, use this instead:
add_filter( 'wpo_wcpdf_invoice_title', 'add_due_date_to_invoice_title', 10, 2 );
function add_due_date_to_invoice_title( $title, $document ) {
if ( ! is_object( $document ) || ! isset( $document->order ) ) return $title;
$order = $document->order;
$user_id = $order->get_user_id();
if ( ! $user_id ) return $title;
$user = get_user_by( 'id', $user_id );
if ( ! in_array( 'wholesalecredit', $user->roles ) ) return $title;
$order_date = $order->get_date_created();
$due_date = $order_date->modify( '+30 days' )->format( get_option( 'date_format' ) );
return $title . ' (Due: ' . $due_date . ')';
}
Where to Place the Code?
- Child Theme:
wp-content/themes/your-child-theme/functions.php - Code Snippets Plugin: Install the Code Snippets plugin for easy management.
- Custom Plugin: Recommended for production sites.
Testing
- Place an order as a
wholesalecredituser. - Generate the PDF invoice and verify the Due Date appears correctly.
Need Adjustments?
- Change the role? Replace
'wholesalecredit'with your desired role (e.g.,'wholesale'). - Different due period? Modify
+30 days(e.g.,'+15 days'). - Styling the output? Add CSS via the plugin’s template files.
Let me know if you’d like help tweaking this further! 🚀

Leave a Reply
You must be logged in to post a comment.