WordPress Plugins for Creators and Online Stores

PDF Invoice & Packing Slip – Developer Documentation

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 in src/vendor/)
  • QR Code Engine: chillerlan/php-qrcode (bundled via Composer in src/vendor/)

Defined in src/wpwing-pdf-invoice-packing-slip-for-woocommerce.php:

ConstantDefault ValuePurpose
WPWING_WCPDF_VERSION'1.20.0'Current plugin version
WPWING_WCPDF_FILE__FILE__Main plugin file path
WPWING_WCPDF_DIRplugin_dir_path( __FILE__ )Plugin root directory
WPWING_WCPDF_DIR_NAMEdirname( plugin_basename( __FILE__ ) )Plugin directory slug
WPWING_WCPDF_BASE_NAMEplugin_basename( __FILE__ )Plugin basename
WPWING_WCPDF_URLplugins_url( '/', __FILE__ )Plugin root URL
WPWING_WCPDF_ASSETS_URLWPWING_WCPDF_URL . 'assets'Assets directory URL
WPWING_WCPDF_TEMPLATE_DIRWPWING_WCPDF_DIR . 'templates/'Built-in PDF templates directory
WPWING_WCPDF_INC_DIRWPWING_WCPDF_DIR . 'includes/'PHP classes directory
WPWING_WCPDF_VENDOR_DIRWPWING_WCPDF_DIR . 'vendor/'Composer vendor directory
WPWING_WCPDF_DOCUMENT_SAVE_DIRwp_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 via wpwing_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, currently 1).
  • wpwing_wcpdf_check_folder_already_protected – flag indicating .htaccess and index.html were 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 a try / finally block that always runs SELECT 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) and index.html. Downscaled product thumbnails are cached in wp-content/uploads/wpwing-pdf-invoices/thumbs/.
  • Font Cache: Dompdf registers DejaVu Sans (all 4 variants) and the bundled WPWing Currency font (src/assets/fonts/WPWingCurrency-Regular.ttf) once into wp-content/uploads/wpwing-pdf-fonts/ (tracked by a fonts_ready_2 marker file) and self-heals if font files are missing.
  • Scheduled Maintenance (WP-Cron): WPWing_WcPdf_Storage schedules a daily event wpwing_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 than pdf_retention_days.

Asset Loading

  • Frontend: The plugin enqueues no frontend CSS or JavaScript.
  • Admin: WPWing_WcPdf_Admin::enqueue_styles() and enqueue_scripts() load wcpdf-admin-css (src/assets/public/css/admin.min.css) and wcpdf-admin-js (src/assets/public/js/admin.min.js, depending on jquery and jquery-ui-sortable) only on plugin screens checked by is_plugin_screen():
  • wpwing-pdf-invoice
  • wpwing_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-orders
  • admin_page_wpwing-wcpdf-wizard
  • When SCRIPT_DEBUG is true, unminified .css and .js files are loaded.

Core Classes (src/includes/)

ClassFileResponsibility
WPWing_WcPdf_Pluginclass-wpwing-wcpdf-plugin.phpBootstrapper, GET action router, document factory (get_document_by_type()), PDF/HTML/UBL streaming
WPWing_WcPdf_Documentclass-wpwing-wcpdf-document.phpAbstract base class for all PDF document types, Dompdf rendering, thumbnails, QR code generation, template hooks
WPWing_WcPdf_Invoiceclass-wpwing-wcpdf-invoice.phpSequential tax invoice document, advisory lock numbering, due date, invoice QR code
WPWing_WcPdf_Proformaclass-wpwing-wcpdf-proforma.phpPre-payment proforma invoice document
WPWing_WcPdf_Packingclass-wpwing-wcpdf-packing.phpPrice-free packing slip document
WPWing_WcPdf_Deliveryclass-wpwing-wcpdf-delivery.phpPrice-free delivery note document
WPWing_WcPdf_Shipping_Labelclass-wpwing-wcpdf-shipping-label.phpPrint-ready shipping label with total weight and optional QR code
WPWing_WcPdf_UBLclass-wpwing-wcpdf-ubl.phpEN 16931 / Peppol BIS Billing 3.0 UBL 2.1 XML generator and file persistence
WPWing_WcPdf_Storageclass-wpwing-wcpdf-storage.phpDaily WP-Cron cleanup (temp archives, thumbnails, retention) and storage diagnostics
WPWing_WcPdf_Adminclass-wpwing-wcpdf-admin.phpOrder edit metabox, admin notices, screen-scoped assets, AJAX live preview
WPWing_WcPdf_Orders_Listclass-wpwing-wcpdf-orders-list.phpOrders list Invoice column, 16 bulk actions (generate, ZIP, merged PDF, UBL ZIP), invoice number search
WPWing_WcPdf_Wc_Hooksclass-wpwing-wcpdf-wc-hooks.phpStatus-change auto-generation, WooCommerce email attachments, My Account order actions
WPWing_WcPdf_Shortcodesclass-wpwing-wcpdf-shortcodes.php[wpwing_invoice] shortcode with context detection and guest order-key verification
WPWing_WcPdf_Settingsclass-wpwing-wcpdf-settings.phpRegisters General, Template, and System Status tabs and fields
WPWing_WcPdf_Settings_APIclass-wpwing-wcpdf-settings-api.phpAdmin menu, settings page form, field rendering, sanitization, theme support overrides
WPWing_WcPdf_Wizardclass-wpwing-wcpdf-wizard.phpFirst-run Setup Wizard (6 steps) and relaunch link
WPWing_WcPdf_Migrationclass-wpwing-wcpdf-migration.phpIdempotent 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 instantiate WPWing_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). Use after_wpwing_wcpdf_settings to 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 is before_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_bar returns true).
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 by WPWing_WcPdf_Wizard to 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.php is 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 hooks add_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's index.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 PatternParametersLocation
wpwing_wcpdf_{type}_template_company_dataNone (use global $wpwing_wcpdf_document)Top-left company details cell
wpwing_wcpdf_{type}_template_company_logoNoneTop-right company logo cell
wpwing_wcpdf_{type}_template_customer_dataNoneLeft recipient / billing / shipping address cell
wpwing_wcpdf_{type}_template_order_dataNoneRight order metadata table cell
wpwing_wcpdf_{type}_template_product_listNoneMain item table and totals block
wpwing_wcpdf_{type}_template_footerNoneNotes 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 proforma documents.
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 (default null), 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 (saved invoice_date_format option; 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 .pdf extension, 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 (default 30), 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 NameFileParametersReturn TypePurpose
wpwing_wcpdf_settings_nameclass-wpwing-wcpdf-settings-api.php:165, class-wpwing-wcpdf-admin.php:417string $setting_name ('wpwing_wcpdf_settings')stringOverride the wp_options key used for settings
wpwing_wcpdf_settings_reset_nameclass-wpwing-wcpdf-settings-api.php:166string $reset_name ('reset')stringOverride the query parameter name for resetting settings
wpwing_wcpdf_settingsclass-wpwing-wcpdf-settings-api.php:170array $fieldsarrayFilter the complete list of registered settings tabs
wpwing_wcpdf_reserved_fieldsclass-wpwing-wcpdf-settings-api.php:172array $reserved (array())arrayField IDs stored separately in *_reserved option
show_wpwing_wcpdf_settings_link_on_admin_barclass-wpwing-wcpdf-settings-api.php:187bool $show (false)boolReturn true to show Invoice Settings in the WP Admin Bar
wpwing_wcpdf_settings_tabclass-wpwing-wcpdf-settings-api.php:457,678array $tabarrayFilter each tab definition before defaults and registration
wpwing_wcpdf_settings_sectionclass-wpwing-wcpdf-settings-api.php:461,682array $section, array $tabarrayFilter each section definition
wpwing_wcpdf_settings_fieldsclass-wpwing-wcpdf-settings-api.php:465,700array $fields, array $section, array $tabarrayFilter fields inside any section
wpwing_wcpdf_settings_{$id}_radio_optionsclass-wpwing-wcpdf-settings-api.php:779array $optionsarrayFilter choices for a specific radio field ID
wpwing_wcpdf_settings_{$id}_select_optionsclass-wpwing-wcpdf-settings-api.php:817array $optionsarrayFilter choices for a specific select field ID
wpwing_wcpdf_settings_{$id}_multiselect_optionsclass-wpwing-wcpdf-settings-api.php:834array $optionsarrayFilter choices for a specific multiselect field ID
wpwing_wcpdf_settings_{$id}_checkboxgroup_optionsclass-wpwing-wcpdf-settings-api.php:854array $optionsarrayFilter choices for a specific checkboxgroup field ID
get_options_tab_css_classesclass-wpwing-wcpdf-settings-api.php:1086array $classesarrayFilter CSS classes on settings nav tabs
wpwing_wcpdf_general_settings_sectionclass-wpwing-wcpdf-settings.php:149array $sectionsarrayFilter sections inside the General tab
wpwing_wcpdf_general_settings_fieldsclass-wpwing-wcpdf-settings.php:155array $fieldsarrayAdd or modify fields in the General tab
wpwing_wcpdf_general_settings_default_activeclass-wpwing-wcpdf-settings.php:313bool $active (true)boolWhether the General tab is active by default
wpwing_wcpdf_template_settings_sectionclass-wpwing-wcpdf-settings.php:327array $sectionsarrayFilter sections inside the Template tab
wpwing_wcpdf_template_settings_fieldsclass-wpwing-wcpdf-settings.php:333array $fieldsarrayAdd or modify fields in the Template tab
wpwing_wcpdf_template_settings_default_activeclass-wpwing-wcpdf-settings.php:607bool $active (false)boolWhether the Template tab is active by default
wpwing_wcpdf_admin_localizeclass-wpwing-wcpdf-admin.php:383array $dataarrayFilter 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, default 0) – Explicit WooCommerce order ID. When omitted or 0, 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 matching key query parameter (WC_Order::get_order_key() on a guest order where customer_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:

  1. 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: "..." } }
  1. 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} and wpwing-download-ubl-invoice={order_id}, each verified with _wpnonce (action wpwing_{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:

SelectorTarget Element
.invoice-documentOuter wrapper for all PDF documents
.proforma-documentAdditional wrapper class on Proforma Invoices
.proforma-bannerTop banner (PROFORMA INVOICE) on Proforma Invoices
.company-headerTop header block containing sender info and logo
.invoice-from-sectionSender details table cell (Invoice From / Ship From / etc.)
.invoice-from-toSection heading label (Invoice From, Invoice To, Ship To, Deliver To, Customer)
.invoice-ship-toAdditional class on the Ship To label
.company-nameStore / company name heading
.company-detailsWrapper around street address, city, ZIP, country, phone, email, and VAT lines
.invoice-logo / .company-logo imgLogo cell and <img> element (default max 200px x 100px)
.invoice-header / .shipping-label-headerRecipient address and order metadata header row
.invoice-to-section / .customer-detailsRecipient address cell and formatted address block
.invoice-dataShaded 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-contentMain content wrapper around the line items table
table.invoice-detailsLine items table (.column-thumbnail, .column-product, .column-sku, .column-weight, .column-quantity, .column-price, .column-total, .column-tax)
table.invoice-totalsSummary totals table (.invoice-details-subtotal, .invoice-details-vat, .invoice-details-total)
.invoice-qrContainer around the QR code <img> (110px x 110px)
.customer-noteCustomer checkout note callout box
.notes / .notes-titleStore notes box above the footer
footerDocument footer block
.woocommerce-Price-currencySymbolCurrency 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

SelectorTarget 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.