This reference is for WordPress developers and agencies integrating with, extending, or styling PDF Invoice and Packing Slip for WooCommerce (version 1.20.0, text domain wpwing-wcpdf).
Technical Architecture Overview
Requirements and Constants
- PHP: 7.4+
- WordPress: 4.8+ (tested up to 7.1)
- WooCommerce: 4.5+ (tested up to 11.3.1)
- PDF Engine:
dompdf/dompdf(bundled via Composer insrc/vendor/) - QR Code Engine:
chillerlan/php-qrcode(bundled via Composer insrc/vendor/)
Defined in src/wpwing-pdf-invoice-packing-slip-for-woocommerce.php:
| Constant | Default Value | Purpose |
|---|---|---|
WPWING_WCPDF_VERSION | '1.20.0' | Current plugin version |
WPWING_WCPDF_FILE | __FILE__ | Main plugin file path |
WPWING_WCPDF_DIR | plugin_dir_path( __FILE__ ) | Plugin root directory |
WPWING_WCPDF_DIR_NAME | dirname( plugin_basename( __FILE__ ) ) | Plugin directory slug |
WPWING_WCPDF_BASE_NAME | plugin_basename( __FILE__ ) | Plugin basename |
WPWING_WCPDF_URL | plugins_url( '/', __FILE__ ) | Plugin root URL |
WPWING_WCPDF_ASSETS_URL | WPWING_WCPDF_URL . 'assets' | Assets directory URL |
WPWING_WCPDF_TEMPLATE_DIR | WPWING_WCPDF_DIR . 'templates/' | Built-in PDF templates directory |
WPWING_WCPDF_INC_DIR | WPWING_WCPDF_DIR . 'includes/' | PHP classes directory |
WPWING_WCPDF_VENDOR_DIR | WPWING_WCPDF_DIR . 'vendor/' | Composer vendor directory |
WPWING_WCPDF_DOCUMENT_SAVE_DIR | wp_upload_dir()['basedir'] . '/wpwing-pdf-invoices/' | Protected directory for saved PDFs, UBL XML, and cached thumbnails |
High-Performance Order Storage (HPOS) Compatibility
The plugin declares full WooCommerce HPOS (custom_order_tables) compatibility on before_woocommerce_init using \Automattic\WooCommerce\Utilities\FeaturesUtil::declare_compatibility( 'custom_order_tables', __FILE__, true ).
- All order reads and writes use
wc_get_order(),$order->get_meta(),$order->update_meta_data(),$order->delete_meta_data(), and$order->save_meta_data(). - The order metabox resolves the active screen via
wc_get_page_screen_id( 'shop-order' ). - Bulk actions, the Invoice orders list column, and order search by invoice number are registered for both classic (
edit-shop_order/shop_order) and HPOS (woocommerce_page_wc-orders) screens.
Database Storage (No Custom Tables)
This plugin creates no custom database tables. All persistent data is stored using native WordPress options and WooCommerce order metadata:
- WordPress Options:
wpwing_wcpdf_settings– serialized associative array of all plugin settings (option name is filterable viawpwing_wcpdf_settings_name).wpwing_wcpdf_settings_reserved– reserved fields persisted separately across saves.wpwing_wcpdf_db_version– migration schema version (WPWing_WcPdf_Migration::DB_VERSION, currently1).wpwing_wcpdf_check_folder_already_protected– flag indicating.htaccessandindex.htmlwere created in the save directory.wpwing_wcpdf_format_migrated_v2– flag indicating legacy[prefix]/[number]/[suffix]tokens were migrated to{number}/{year}/{month}.wpwing_wcpdf_wizard_completed– flag indicating the Setup Wizard was completed or skipped.- Order Meta Keys (HPOS and Classic):
- Invoice:
_wpwing_wcpdf_invoiced,_wpwing_wcpdf_invoice_number,_wpwing_wcpdf_invoice_prefix,_wpwing_wcpdf_invoice_suffix,_wpwing_wcpdf_invoice_date,_wpwing_wcpdf_invoice_path,_wpwing_wcpdf_pending_invoice_number,_wpwing_wcpdf_invoice_ubl_path. - Proforma:
_wpwing_wcpdf_proforma,_wpwing_wcpdf_proforma_path,_wpwing_wcpdf_proforma_number,_wpwing_wcpdf_proforma_date. - Packing Slip:
_wpwing_wcpdf_packing,_wpwing_wcpdf_packing_path. - Delivery Note:
_wpwing_wcpdf_delivery,_wpwing_wcpdf_delivery_path. - Shipping Label:
_wpwing_wcpdf_shipping_label,_wpwing_wcpdf_shipping_label_path.
Concurrency, File Storage, and Background Maintenance
- Atomic Invoice Numbering:
WPWing_WcPdf_Invoice::get_new_invoice_number()acquires a MySQL advisory lock (SELECT GET_LOCK('wpwing_wcpdf_invoice_number', 5)) wrapped in atry / finallyblock that always runsSELECT RELEASE_LOCK(...). Yearly resets run inside the same lock. - Protected Upload Storage: Generated PDFs and UBL 2.1 XML files are saved under
wp-content/uploads/wpwing-pdf-invoices/{YYYY}/, protected by.htaccess(deny from all) andindex.html. Downscaled product thumbnails are cached inwp-content/uploads/wpwing-pdf-invoices/thumbs/. - Font Cache: Dompdf registers
DejaVu Sans(all 4 variants) and the bundledWPWing Currencyfont (src/assets/fonts/WPWingCurrency-Regular.ttf) once intowp-content/uploads/wpwing-pdf-fonts/(tracked by afonts_ready_2marker file) and self-heals if font files are missing. - Scheduled Maintenance (WP-Cron):
WPWing_WcPdf_Storageschedules a daily eventwpwing_wcpdf_daily_storage_cleanup(cleared on plugin deactivation) that purges stale bulk temp archives (> 24 hours), cached thumbnails (> 30 days), and expired PDF/XML documents older thanpdf_retention_days.
Asset Loading
- Frontend: The plugin enqueues no frontend CSS or JavaScript.
- Admin:
WPWing_WcPdf_Admin::enqueue_styles()andenqueue_scripts()loadwcpdf-admin-css(src/assets/public/css/admin.min.css) andwcpdf-admin-js(src/assets/public/js/admin.min.js, depending onjqueryandjquery-ui-sortable) only on plugin screens checked byis_plugin_screen(): wpwing-pdf-invoicewpwing_page_wpwing-pdf-invoice-packing-slip-for-woocommerce-settings- WooCommerce single order screen (
wc_get_page_screen_id( 'shop-order' )/shop_order) woocommerce_page_wc-ordersadmin_page_wpwing-wcpdf-wizard- When
SCRIPT_DEBUGistrue, unminified.cssand.jsfiles are loaded.
Core Classes (src/includes/)
| Class | File | Responsibility |
|---|---|---|
WPWing_WcPdf_Plugin | class-wpwing-wcpdf-plugin.php | Bootstrapper, GET action router, document factory (get_document_by_type()), PDF/HTML/UBL streaming |
WPWing_WcPdf_Document | class-wpwing-wcpdf-document.php | Abstract base class for all PDF document types, Dompdf rendering, thumbnails, QR code generation, template hooks |
WPWing_WcPdf_Invoice | class-wpwing-wcpdf-invoice.php | Sequential tax invoice document, advisory lock numbering, due date, invoice QR code |
WPWing_WcPdf_Proforma | class-wpwing-wcpdf-proforma.php | Pre-payment proforma invoice document |
WPWing_WcPdf_Packing | class-wpwing-wcpdf-packing.php | Price-free packing slip document |
WPWing_WcPdf_Delivery | class-wpwing-wcpdf-delivery.php | Price-free delivery note document |
WPWing_WcPdf_Shipping_Label | class-wpwing-wcpdf-shipping-label.php | Print-ready shipping label with total weight and optional QR code |
WPWing_WcPdf_UBL | class-wpwing-wcpdf-ubl.php | EN 16931 / Peppol BIS Billing 3.0 UBL 2.1 XML generator and file persistence |
WPWing_WcPdf_Storage | class-wpwing-wcpdf-storage.php | Daily WP-Cron cleanup (temp archives, thumbnails, retention) and storage diagnostics |
WPWing_WcPdf_Admin | class-wpwing-wcpdf-admin.php | Order edit metabox, admin notices, screen-scoped assets, AJAX live preview |
WPWing_WcPdf_Orders_List | class-wpwing-wcpdf-orders-list.php | Orders list Invoice column, 16 bulk actions (generate, ZIP, merged PDF, UBL ZIP), invoice number search |
WPWing_WcPdf_Wc_Hooks | class-wpwing-wcpdf-wc-hooks.php | Status-change auto-generation, WooCommerce email attachments, My Account order actions |
WPWing_WcPdf_Shortcodes | class-wpwing-wcpdf-shortcodes.php | [wpwing_invoice] shortcode with context detection and guest order-key verification |
WPWing_WcPdf_Settings | class-wpwing-wcpdf-settings.php | Registers General, Template, and System Status tabs and fields |
WPWing_WcPdf_Settings_API | class-wpwing-wcpdf-settings-api.php | Admin menu, settings page form, field rendering, sanitization, theme support overrides |
WPWing_WcPdf_Wizard | class-wpwing-wcpdf-wizard.php | First-run Setup Wizard (6 steps) and relaunch link |
WPWing_WcPdf_Migration | class-wpwing-wcpdf-migration.php | Idempotent migration from legacy wpwing_wcpi_* options and order meta |
Action Hooks (do_action)
Lifecycle and Settings Actions
wpwing_wcpdf_init
- File:
src/wpwing-pdf-invoice-packing-slip-for-woocommerce.php(line 165) - Parameters: None
- Description: Fires on
plugins_loaded(priority 11) when WooCommerce is active, to load classes and instantiateWPWing_WcPdf_Plugin.
add_action( 'wpwing_wcpdf_init', function () {
// Run custom initialization after WooCommerce is confirmed active.
}, 20 );
wpwing_wcpdf_settings_init
- File:
src/includes/class-wpwing-wcpdf-settings.php(line 36) - Parameters:
WPWing_WcPdf_Settings $settings - Description: Fires at the end of
WPWing_WcPdf_Settings::__construct().
add_action( 'wpwing_wcpdf_settings_init', function ( $settings ) {
// Access $settings instance early in the plugin lifecycle.
} );
before_wpwing_wcpdf_settings / after_wpwing_wcpdf_settings
- File:
src/includes/class-wpwing-wcpdf-settings.php(lines 80, 90) - Parameters:
WPWing_WcPdf_Settings $settings - Description: Fire immediately before and after the built-in General, Template, and System Status tabs are registered on
init(priority 2). Useafter_wpwing_wcpdf_settingsto register a custom settings tab via$settings->add_setting().
add_action( 'after_wpwing_wcpdf_settings', function ( $settings ) {
$settings->add_setting(
'my_custom_tab',
__( 'Custom Integration', 'my-textdomain' ),
array(
array(
'title' => __( 'ERP Export', 'my-textdomain' ),
'desc' => __( 'Configure external ERP synchronization.', 'my-textdomain' ),
'fields' => array(
array(
'id' => 'erp_endpoint_url',
'type' => 'text',
'title' => __( 'Endpoint URL:', 'my-textdomain' ),
'default' => '',
),
),
),
),
false
);
} );
wpwing_wcpdf_setting_api_init
- File:
src/includes/class-wpwing-wcpdf-settings-api.php(line 193) - Parameters:
WPWing_WcPdf_Settings_API $settings_api - Description: Fires at the end of
WPWing_WcPdf_Settings_API::__construct().
add_action( 'wpwing_wcpdf_setting_api_init', function ( $settings_api ) {
// Inspect or hook into the settings API instance.
} );
before_update_{$settings_name}_settings
- File:
src/includes/class-wpwing-wcpdf-settings-api.php(line 244) - Parameters:
WPWing_WcPdf_Settings_API $settings_api - Description: Fires inside
pre_update_option_{$settings_name}before settings are saved. With the default option name (wpwing_wcpdf_settings), the hook name isbefore_update_wpwing_wcpdf_settings_settings.
add_action( 'before_update_wpwing_wcpdf_settings_settings', function ( $settings_api ) {
// Flush custom caches before plugin settings are saved.
} );
delete_{$settings_name}_settings
- File:
src/includes/class-wpwing-wcpdf-settings-api.php(line 488) - Parameters:
WPWing_WcPdf_Settings_API $settings_api - Description: Fires right before
delete_option()runs when an administrator clicks Reset all. Default hook name:delete_wpwing_wcpdf_settings_settings.
add_action( 'delete_wpwing_wcpdf_settings_settings', function ( $settings_api ) {
// Clean up custom add-on options when plugin settings are reset.
} );
wpwing_wcpdf_admin_bar_menu
- File:
src/includes/class-wpwing-wcpdf-settings-api.php(line 374) - Parameters:
WP_Admin_Bar $wp_admin_bar,string $settings_name - Description: Fires after adding the plugin's admin bar item (only when
show_wpwing_wcpdf_settings_link_on_admin_barreturnstrue).
add_filter( 'show_wpwing_wcpdf_settings_link_on_admin_bar', '__return_true' );
add_action( 'wpwing_wcpdf_admin_bar_menu', function ( $wp_admin_bar, $settings_name ) {
$wp_admin_bar->add_menu(
array(
'id' => 'my-wcpdf-orders',
'title' => __( 'WooCommerce Orders', 'my-textdomain' ),
'href' => admin_url( 'edit.php?post_type=shop_order' ),
'parent' => $settings_name,
)
);
}, 10, 2 );
wpwing_wcpdf_settings_field_callback
- File:
src/includes/class-wpwing-wcpdf-settings-api.php(line 912) - Parameters:
array $args(field definition array) - Description: Fires immediately after each settings field is rendered.
add_action( 'wpwing_wcpdf_settings_field_callback', function ( $args ) {
if ( isset( $args['id'] ) && 'company_vat' === $args['id'] ) {
echo '<p class="description">' . esc_html__( 'Include your 2-letter EU country prefix (e.g., DE123456789).', 'my-textdomain' ) . '</p>';
}
} );
wpwing_wcpdf_settings_before_form
- File:
src/includes/class-wpwing-wcpdf-settings-api.php(line 950) - Parameters:
WPWing_WcPdf_Settings_API $settings_api - Description: Fires inside the settings page wrapper right below the
<h1>heading and above the search box. Used internally byWPWing_WcPdf_Wizardto render the Re-launch Setup Wizard link.
add_action( 'wpwing_wcpdf_settings_before_form', function () {
echo '<p class="description">' . esc_html__( 'Custom agency notice above Invoice Settings.', 'my-textdomain' ) . '</p>';
} );
Document Template Generation Actions
When rendering any document, the global $wpwing_wcpdf_document holds the active WPWing_WcPdf_Document subclass instance (with $wpwing_wcpdf_document->order containing the WC_Order). Since version 1.17.0, flush_template() only removes the plugin's own callbacks, leaving third-party callbacks intact across bulk runs.
wpwing_wcpdf_before_template_generation
- File:
src/includes/class-wpwing-wcpdf-document.php(line 155) - Parameters: None (access
global $wpwing_wcpdf_document) - Description: Fires right before
template.phpis loaded during PDF generation.
add_action( 'wpwing_wcpdf_before_template_generation', function () {
global $wpwing_wcpdf_document;
if ( $wpwing_wcpdf_document && 'invoice' === $wpwing_wcpdf_document->document_type ) {
// Prepare custom data before rendering an invoice PDF.
}
} );
wpwing_wcpdf_template_head
- File:
src/templates/default/template.php(line 32),src/templates/modern/template.php(line 25) - Parameters: None
- Description: Fires inside the
<head>of the PDF HTML document. The plugin hooksadd_template_head()at priority 10 to output the template CSS and Custom CSS.
add_action( 'wpwing_wcpdf_template_head', function () {
echo '<style>.company-name { color: #0b5394; }</style>';
}, 20 );
wpwing_wcpdf_template_content
- File:
src/templates/default/template.php(line 44),src/templates/modern/template.php(line 29) - Parameters: None
- Description: Fires inside the
<body>of the PDF HTML document to render the document'sindex.php.
add_action( 'wpwing_wcpdf_template_content', function () {
echo '<div style="text-align:center;font-size:11px;color:#666;">Thank you for your business!</div>';
}, 20 );
Per-Document Template Section Actions
Every document type (invoice, packing, delivery, shipping_label, proforma) fires six section hooks inside src/templates/{theme}/{doc_type}/index.php (in both default and modern templates). The plugin hooks its own renderers at priority 10.
| Hook Pattern | Parameters | Location |
|---|---|---|
wpwing_wcpdf_{type}_template_company_data | None (use global $wpwing_wcpdf_document) | Top-left company details cell |
wpwing_wcpdf_{type}_template_company_logo | None | Top-right company logo cell |
wpwing_wcpdf_{type}_template_customer_data | None | Left recipient / billing / shipping address cell |
wpwing_wcpdf_{type}_template_order_data | None | Right order metadata table cell |
wpwing_wcpdf_{type}_template_product_list | None | Main item table and totals block |
wpwing_wcpdf_{type}_template_footer | None | Notes and footer block |
Replace {type} with invoice, packing, delivery, shipping_label, or proforma.
// Display a custom VAT number meta field below the customer address on invoices.
add_action( 'wpwing_wcpdf_invoice_template_customer_data', function () {
global $wpwing_wcpdf_document;
if ( ! $wpwing_wcpdf_document || ! $wpwing_wcpdf_document->order ) {
return;
}
$vat = $wpwing_wcpdf_document->order->get_meta( '_billing_vat_number' );
if ( $vat ) {
echo '<div class="customer-vat"><strong>' . esc_html__( 'VAT ID:', 'my-textdomain' ) . '</strong> ' . esc_html( $vat ) . '</div>';
}
}, 20 );
Filter Hooks (apply_filters)
Document, Numbering, and File Filters
wpwing_wcpdf_proforma_class
- File:
src/includes/class-wpwing-wcpdf-plugin.php(line 209) - Parameters:
string $class(default'WPWing_WcPdf_Proforma') - Return Type:
string - Description: Override or extend the PHP class instantiated for
proformadocuments.
add_filter( 'wpwing_wcpdf_proforma_class', function ( $class ) {
return 'My_Custom_Proforma_Document';
} );
wpwing_wcpdf_new_invoice_number
- File:
src/includes/class-wpwing-wcpdf-invoice.php(line 249) - Parameters:
int|string|null $invoice_number(defaultnull),WC_Order $order - Return Type:
int|string|null - Description: Supply a custom invoice number when an invoice is first saved. Return a non-empty value to bypass the built-in sequential counter.
add_filter( 'wpwing_wcpdf_new_invoice_number', function ( $invoice_number, $order ) {
// Use the WooCommerce order number instead of the sequential counter.
return $order->get_order_number();
}, 10, 2 );
wpwing_wcpdf_get_formatted_invoice_number
- File:
src/includes/class-wpwing-wcpdf-invoice.php(line 145) - Parameters:
string $formatted,WC_Order $order - Return Type:
string - Description: Filter the final formatted invoice number string after token replacement.
add_filter( 'wpwing_wcpdf_get_formatted_invoice_number', function ( $formatted, $order ) {
// Zero-pad numeric-only invoice numbers to 5 digits.
if ( ctype_digit( $formatted ) ) {
return str_pad( $formatted, 5, '0', STR_PAD_LEFT );
}
return $formatted;
}, 10, 2 );
wpwing_wcpdf_get_formatted_proforma_number
- File:
src/includes/class-wpwing-wcpdf-proforma.php(line 99) - Parameters:
string $formatted(default'PRO-' . $number),WC_Order $order,WPWing_WcPdf_Proforma $proforma - Return Type:
string - Description: Customize the formatted display number on proforma invoices.
add_filter( 'wpwing_wcpdf_get_formatted_proforma_number', function ( $formatted, $order ) {
return 'PF-' . gmdate( 'Y' ) . '-' . $order->get_order_number();
}, 10, 2 );
wpwing_wcpdf_invoice_date_format
- File:
src/includes/class-wpwing-wcpdf-document.php(line 302) - Parameters:
string $format(savedinvoice_date_formatoption; falls back to'd/m/Y') - Return Type:
string - Description: Filter the PHP date format string used by
WPWing_WcPdf_Document::get_formatted_date().
add_filter( 'wpwing_wcpdf_invoice_date_format', function () {
return 'Y-m-d';
} );
Document Filename Filters
- Files:
wpwing_wcpdf_invoice_filename–src/includes/class-wpwing-wcpdf-invoice.php(line 265)wpwing_wcpdf_packing_filename–src/includes/class-wpwing-wcpdf-packing.php(line 117)wpwing_wcpdf_delivery_filename–src/includes/class-wpwing-wcpdf-delivery.php(line 117)wpwing_wcpdf_shipping_label_filename–src/includes/class-wpwing-wcpdf-shipping-label.php(line 119)wpwing_wcpdf_proforma_filename–src/includes/class-wpwing-wcpdf-proforma.php(line 151)- Parameters:
string $filename(with leading slash, without.pdfextension, e.g.'/invoice_42'),WPWing_WcPdf_Document $document - Return Type:
string - Description: Filter the filename (relative to the year folder) before the PDF is written to disk.
add_filter( 'wpwing_wcpdf_invoice_filename', function ( $filename, $document ) {
return '/INV-' . sanitize_file_name( $document->order->get_order_number() );
}, 10, 2 );
wpwing_wcpdf_pdf_theme_dir
- File:
src/includes/class-wpwing-wcpdf-document.php(line 103) - Parameters:
string $theme_dir(absolute path with trailing slash),string $document_type - Return Type:
string - Description: Point a document type to a custom template directory inside your child theme or custom plugin.
add_filter( 'wpwing_wcpdf_pdf_theme_dir', function ( $theme_dir, $document_type ) {
$custom_dir = trailingslashit( get_stylesheet_directory() ) . 'wpwing-wcpdf/';
if ( is_dir( $custom_dir ) && 'invoice' === $document_type ) {
return $custom_dir;
}
return $theme_dir;
}, 10, 2 );
wpwing_wcpdf_company_image_path
- File:
src/includes/class-wpwing-wcpdf-document.php(line 557) - Parameters:
string $company_logo(configured logo URL) - Return Type:
string - Description: Filter the company logo URL before it is resolved to a local base64 data URI for Dompdf.
add_filter( 'wpwing_wcpdf_company_image_path', function ( $logo_url ) {
return $logo_url;
} );
wpwing_wcpdf_merged_pdf_max_orders
- File:
src/includes/class-wpwing-wcpdf-orders-list.php(lines 141, 342) - Parameters:
int $max_orders(default30),string $document_type - Return Type:
int - Description: Control the maximum number of orders processed in a single Merged PDF bulk download run to protect PHP memory limits.
add_filter( 'wpwing_wcpdf_merged_pdf_max_orders', function ( $limit, $document_type ) {
return 50;
}, 10, 2 );
UBL 2.1 e-Invoicing Filters
wpwing_wcpdf_ubl_customization_id
- File:
src/includes/class-wpwing-wcpdf-ubl.php(line 118) - Parameters:
string $customization_id(default'urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0'),WC_Order $order,WPWing_WcPdf_Invoice|null $invoice - Return Type:
string - Description: Filter the
<cbc:CustomizationID>value in generated UBL 2.1 XML.
add_filter( 'wpwing_wcpdf_ubl_customization_id', function ( $id, $order ) {
return 'urn:cen.eu:en16931:2017#compliant#urn:xeinkauf.de:kosit:xrechnung_3.0';
}, 10, 2 );
wpwing_wcpdf_ubl_profile_id
- File:
src/includes/class-wpwing-wcpdf-ubl.php(line 124) - Parameters:
string $profile_id(default'urn:fdc:peppol.eu:2017:poacc:billing:01:1.0'),WC_Order $order,WPWing_WcPdf_Invoice|null $invoice - Return Type:
string - Description: Filter the
<cbc:ProfileID>value in generated UBL 2.1 XML.
add_filter( 'wpwing_wcpdf_ubl_profile_id', function ( $profile_id ) {
return 'urn:fdc:peppol.eu:2017:poacc:billing:01:1.0';
} );
wpwing_wcpdf_ubl_payment_means_code
- File:
src/includes/class-wpwing-wcpdf-ubl.php(line 432) - Parameters:
string $code(UN/ECE 4461 code:'30'bank/cheque,'10'cash/COD,'48'card,'1'default),string $payment_method,WC_Order $order - Return Type:
string - Description: Map custom WooCommerce payment gateways to UN/ECE 4461 payment means codes.
add_filter( 'wpwing_wcpdf_ubl_payment_means_code', function ( $code, $payment_method ) {
if ( 'mollie_wc_gateway_ideal' === $payment_method ) {
return '30';
}
return $code;
}, 10, 2 );
wpwing_wcpdf_ubl_xml
- File:
src/includes/class-wpwing-wcpdf-ubl.php(line 169) - Parameters:
string $xml,WC_Order $order,WPWing_WcPdf_Invoice|null $invoice - Return Type:
string - Description: Modify the generated UBL 2.1 XML string before it is saved or streamed.
add_filter( 'wpwing_wcpdf_ubl_xml', function ( $xml, $order ) {
// Post-process or sign the generated XML string.
return $xml;
}, 10, 2 );
Settings and Admin UI Filters
| Filter Name | File | Parameters | Return Type | Purpose |
|---|---|---|---|---|
wpwing_wcpdf_settings_name | class-wpwing-wcpdf-settings-api.php:165, class-wpwing-wcpdf-admin.php:417 | string $setting_name ('wpwing_wcpdf_settings') | string | Override the wp_options key used for settings |
wpwing_wcpdf_settings_reset_name | class-wpwing-wcpdf-settings-api.php:166 | string $reset_name ('reset') | string | Override the query parameter name for resetting settings |
wpwing_wcpdf_settings | class-wpwing-wcpdf-settings-api.php:170 | array $fields | array | Filter the complete list of registered settings tabs |
wpwing_wcpdf_reserved_fields | class-wpwing-wcpdf-settings-api.php:172 | array $reserved (array()) | array | Field IDs stored separately in *_reserved option |
show_wpwing_wcpdf_settings_link_on_admin_bar | class-wpwing-wcpdf-settings-api.php:187 | bool $show (false) | bool | Return true to show Invoice Settings in the WP Admin Bar |
wpwing_wcpdf_settings_tab | class-wpwing-wcpdf-settings-api.php:457,678 | array $tab | array | Filter each tab definition before defaults and registration |
wpwing_wcpdf_settings_section | class-wpwing-wcpdf-settings-api.php:461,682 | array $section, array $tab | array | Filter each section definition |
wpwing_wcpdf_settings_fields | class-wpwing-wcpdf-settings-api.php:465,700 | array $fields, array $section, array $tab | array | Filter fields inside any section |
wpwing_wcpdf_settings_{$id}_radio_options | class-wpwing-wcpdf-settings-api.php:779 | array $options | array | Filter choices for a specific radio field ID |
wpwing_wcpdf_settings_{$id}_select_options | class-wpwing-wcpdf-settings-api.php:817 | array $options | array | Filter choices for a specific select field ID |
wpwing_wcpdf_settings_{$id}_multiselect_options | class-wpwing-wcpdf-settings-api.php:834 | array $options | array | Filter choices for a specific multiselect field ID |
wpwing_wcpdf_settings_{$id}_checkboxgroup_options | class-wpwing-wcpdf-settings-api.php:854 | array $options | array | Filter choices for a specific checkboxgroup field ID |
get_options_tab_css_classes | class-wpwing-wcpdf-settings-api.php:1086 | array $classes | array | Filter CSS classes on settings nav tabs |
wpwing_wcpdf_general_settings_section | class-wpwing-wcpdf-settings.php:149 | array $sections | array | Filter sections inside the General tab |
wpwing_wcpdf_general_settings_fields | class-wpwing-wcpdf-settings.php:155 | array $fields | array | Add or modify fields in the General tab |
wpwing_wcpdf_general_settings_default_active | class-wpwing-wcpdf-settings.php:313 | bool $active (true) | bool | Whether the General tab is active by default |
wpwing_wcpdf_template_settings_section | class-wpwing-wcpdf-settings.php:327 | array $sections | array | Filter sections inside the Template tab |
wpwing_wcpdf_template_settings_fields | class-wpwing-wcpdf-settings.php:333 | array $fields | array | Add or modify fields in the Template tab |
wpwing_wcpdf_template_settings_default_active | class-wpwing-wcpdf-settings.php:607 | bool $active (false) | bool | Whether the Template tab is active by default |
wpwing_wcpdf_admin_localize | class-wpwing-wcpdf-admin.php:383 | array $data | array | Filter the wpwing_wcpdf_object JS object localized to wcpdf-admin-js |
// Example: add a custom WooCommerce email ID to the "Attach invoice PDF to emails" checkbox group.
add_filter( 'wpwing_wcpdf_settings_invoice_attach_to_emails_checkboxgroup_options', function ( $options ) {
$options['new_order'] = __( 'New Order (Admin)', 'my-textdomain' );
return $options;
} );
Theme Support Overrides
WPWing_WcPdf_Settings_API::get_option() checks current_theme_supports( 'wpwing-wcpdf' ). Themes can provide default option overrides via add_theme_support():
add_action( 'after_setup_theme', function () {
add_theme_support(
'wpwing-wcpdf',
array(
'invoice_template' => 'modern',
'paper_size' => 'letter',
)
);
} );
Shortcodes, Gutenberg Blocks, and REST API Endpoints
Shortcodes
[wpwing_invoice]
- Class / File:
WPWing_WcPdf_Shortcodes(src/includes/class-wpwing-wcpdf-shortcodes.php) - Attributes:
order_id(int, default0) – Explicit WooCommerce order ID. When omitted or0, the shortcode auto-detects the order from$wp->query_vars['order-received'](Thank You page) or$wp->query_vars['view-order'](My Account order detail page).label(string, default'Download Invoice') – Visible anchor text.- Output:
<a class="wpwing-wcpdf-invoice-link" href="{nonce_url}">{label}</a> - Access Control: Renders an empty string if the order cannot be resolved, no invoice exists yet, or the current visitor is not an admin (
manage_woocommerce), the logged-in order customer, or a guest with a valid matchingkeyquery parameter (WC_Order::get_order_key()on a guest order wherecustomer_id === 0).
// Render inside a PHP template on a custom order page:
echo do_shortcode( '[wpwing_invoice order_id="123" label="Download Your Tax Invoice"]' );
Gutenberg Blocks
This plugin does not register any Gutenberg blocks. To embed an invoice download link inside the Block Editor, insert a standard Shortcode block containing [wpwing_invoice].
REST API Endpoints
This plugin does not register any WordPress REST API (register_rest_route) endpoints.
Instead, document operations use:
- Admin AJAX Endpoint (
wp_ajax_wpwing_preview_document):
- Handler:
WPWing_WcPdf_Admin::ajax_preview_document()(src/includes/class-wpwing-wcpdf-admin.php) - Security:
check_ajax_referer( 'wpwing_preview_document', 'nonce' )+current_user_can( 'manage_woocommerce' ) - POST Parameters:
nonce,document_type(default'invoice'),preview_overrides(optional associative array of unsaved settings values) - Response: JSON
{ success: true, data: { html: "..." } }
- Nonce-Protected Document GET Endpoints (
init):
- Handled in
WPWing_WcPdf_Plugin::init_plugin_actions()(src/includes/class-wpwing-wcpdf-plugin.php). - Query parameters:
wpwing-{create|view|reset|preview-html}-{invoice|packing|delivery|shipping-label|proforma}={order_id}andwpwing-download-ubl-invoice={order_id}, each verified with_wpnonce(actionwpwing_{op}_{doc_type}_{order_id}) and capability/ownership checks.
CSS Classes and Custom Properties
CSS Custom Properties
This plugin defines no CSS custom properties (--*). Because Dompdf has limited support for CSS variables, all PDF template stylesheets and admin styles use explicit CSS rules and class selectors.
PDF Document Template Classes
Use these classes in WPWing > Invoice Settings > Template > Custom CSS (loaded after the active template's style.css for all five document types) or in custom template overrides:
| Selector | Target Element |
|---|---|
.invoice-document | Outer wrapper for all PDF documents |
.proforma-document | Additional wrapper class on Proforma Invoices |
.proforma-banner | Top banner (PROFORMA INVOICE) on Proforma Invoices |
.company-header | Top header block containing sender info and logo |
.invoice-from-section | Sender details table cell (Invoice From / Ship From / etc.) |
.invoice-from-to | Section heading label (Invoice From, Invoice To, Ship To, Deliver To, Customer) |
.invoice-ship-to | Additional class on the Ship To label |
.company-name | Store / company name heading |
.company-details | Wrapper around street address, city, ZIP, country, phone, email, and VAT lines |
.invoice-logo / .company-logo img | Logo cell and <img> element (default max 200px x 100px) |
.invoice-header / .shipping-label-header | Recipient address and order metadata header row |
.invoice-to-section / .customer-details | Recipient address cell and formatted address block |
.invoice-data | Shaded metadata box on the right (tr.invoice-number, tr.invoice-order-number, tr.invoice-date, tr.invoice-due-date, tr.invoice-amount, tr.invoice-weight, tr.invoice-shipping-method) |
.invoice-content | Main content wrapper around the line items table |
table.invoice-details | Line items table (.column-thumbnail, .column-product, .column-sku, .column-weight, .column-quantity, .column-price, .column-total, .column-tax) |
table.invoice-totals | Summary totals table (.invoice-details-subtotal, .invoice-details-vat, .invoice-details-total) |
.invoice-qr | Container around the QR code <img> (110px x 110px) |
.customer-note | Customer checkout note callout box |
.notes / .notes-title | Store notes box above the footer |
footer | Document footer block |
.woocommerce-Price-currencySymbol | Currency symbol span (uses font-family: WPWing Currency, DejaVu Sans, sans-serif;) |
/* Example Custom CSS snippet for Template Settings */
.company-name {
font-size: 20px;
color: #0f172a;
}
table.invoice-details thead {
background-color: #0f172a;
}
.invoice-details-total {
background-color: #0f172a;
color: #ffffff;
}
Frontend Shortcode Class
| Selector | Target Element |
|---|---|
.wpwing-wcpdf-invoice-link | <a> element output by the [wpwing_invoice] shortcode |
/* Example theme stylesheet rule for the shortcode button */
a.wpwing-wcpdf-invoice-link {
display: inline-block;
padding: 10px 18px;
background: #2271b1;
color: #ffffff;
text-decoration: none;
border-radius: 4px;
}
Admin UI Classes (src/assets/src/scss/admin.scss)
- Order Metabox:
.wpwing-wcpdf-metabox,.wpwing-wcpdf-summary,.wpwing-wcpdf-doc-row,.wpwing-wcpdf-doc-icon,.wpwing-wcpdf-doc-label,.wpwing-wcpdf-doc-actions,.wpwing_wcpdf_create_invoice,.wpwing_wcpdf_view_invoice,.wpwing_wcpdf_preview_html,.wpwing_wcpdf_download_ubl,.wpwing-btn-cancel. - Orders List Column:
.column-wpwing_invoice. - Settings Screen:
.wpwing-settings-layout,.wpwing-settings-left,.wpwing-settings-right,.wpwing-preview-header,.wpwing-wcpdf-settings-search,.wpwing-checkboxgroup,.wpwing-status-table,.wpwing-status-ok,.wpwing-status-warn. - Setup Wizard:
.wpwing-wizard-wrap,.wpwing-wizard-steps,.wpwing-wizard-step-current,.wpwing-wizard-card,.wpwing-wizard-actions.
