WPRuby Packing Slips can be changed from a theme or a small plugin, without editing its files: copy a template into your theme, or use the filters and actions below.
Overriding templates
Copy a file from the plugin’s templates/ folder to yourtheme/wpruby-packing-slips/, keeping the same path, and edit the copy. For example, copy templates/parts/items-table.php to yourtheme/wpruby-packing-slips/parts/items-table.php.
| Template | What it prints |
|---|---|
document.php | The whole page: styles, the print-view toolbar and every slip. |
packing-slip.php | One slip: header, addresses, tracking, items and footer. |
parts/box-header.php | The “Box 1 of 2” panel. |
parts/items-table.php | The items table and totals. |
Templates receive $slip (the slip data as an array), $settings, $renderer, $context (html or pdf) and $loader. After an update, compare your copies with the new templates.
Filters and actions
| Hook | Type | Arguments |
|---|---|---|
wpruby_ps_shipping_providers | filter | Array of shipping data providers. Add your own for another carrier. |
wpruby_ps_packed_boxes | filter | $boxes (Packed_Box objects), $order, $shipping_item |
wpruby_ps_slip_data | filter | $data (array), $slip |
wpruby_ps_item_columns | filter | $columns (key => label), $slip |
wpruby_ps_item_column_value | filter | $html, $key, $item, $slip |
wpruby_ps_before_slip / wpruby_ps_after_slip | action | $slip, $context (html or pdf) |
wpruby_ps_css | filter | $css, $context |
wpruby_ps_pdf_options | filter | dompdf options array |
wpruby_ps_max_pdf_orders | filter | Most orders in one PDF. Default 50, never above 200. |
wpruby_ps_template_path | filter | $path, $name |
wpruby_ps_template_args | filter | $args, $name |
Example: add a column
This adds a “Bin” column filled from a product custom field called _bin_location. Return plain text: the plugin escapes cell values when it prints them.
add_filter( 'wpruby_ps_item_columns', function ( $columns ) {
$columns['bin'] = 'Bin';
return $columns;
} );
add_filter( 'wpruby_ps_item_column_value', function ( $html, $key, $item ) {
if ( 'bin' !== $key ) {
return $html;
}
$product_id = $item['variation_id'] ? $item['variation_id'] : $item['product_id'];
return (string) get_post_meta( $product_id, '_bin_location', true );
}, 10, 3 );
Example: change the slip styles
add_filter( 'wpruby_ps_css', function ( $css ) {
return $css . '.ps-items td { font-size: 12pt; }';
} );
Example: allow larger PDFs
add_filter( 'wpruby_ps_max_pdf_orders', function () {
return 100;
} );
Check your server’s memory limit first: a 50-order PDF took about 2 seconds and 66 MB on a test store.
Adding a shipping provider
To print per-box slips for another shipping plugin, add a class that implements WPRuby\PackingSlips\Providers\Shipping_Data_Provider and register it. The interface has six methods: id(), supports( $shipping_item ) (true for your plugin’s shipping method), carrier_name(), service_name( $shipping_item ), boxes( $order, $shipping_item ) and tracking_numbers( $order ).
add_filter( 'wpruby_ps_shipping_providers', function ( array $providers ) {
$providers[] = new My_Carrier_Provider();
return $providers;
} );
Its boxes() method returns Packed_Box objects built from the data your shipping plugin stores:
use WPRuby\PackingSlips\Document\Packed_Box;
Packed_Box::from_array( array(
'name' => 'Medium Box',
'length' => 30,
'width' => 25,
'height' => 15,
'dimension_unit' => 'cm',
'weight' => 1.15,
'weight_unit' => 'kg',
'tracking_number' => 'ABC123',
'items' => array(
array( 'product_id' => 12, 'variation_id' => 0, 'sku' => 'MUG', 'name' => 'Coffee Mug', 'qty' => 3 ),
),
) );
Items are matched to order lines by order item ID (order_item_id, the most exact), then variation ID, product ID, SKU and finally name. Extend WPRuby\PackingSlips\Providers\Abstract_Provider for helpers that decode stored JSON and serialized values safely.