Plugin Contributor
Ewout
(@pomegranate)
Hi!
Unfortunately this is not possible with the plugin, but I have a small bit of code that I wrote for another customer that you can use for this purpose. You have to put this into your theme functions (functions.php). Read this if you haven’t edited that file before!
add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_packing_slip_number', 10, 2 );
function wpo_wcpdf_packing_slip_number ($template_type, $order) {
global $wpo_wcpdf;
if ($template_type == 'packing-slip') {
// get number from order
$ps_number = get_post_meta( $order->id, 'Packing Slip Number', true );
// get number from database if no number present yet
if (empty($ps_number)) {
$ps_number = get_option( 'wcpdf_next_packing_slip_number', 1001 ); // change 1001 to define the first number
// store number in order
update_post_meta($order->id, 'Packing Slip Number', $ps_number);
// increase packing slip number in database
update_option( 'wcpdf_next_packing_slip_number', $ps_number+1 );
}
?>
<tr class="packing-slip-number">
<th>Packing Slip Number:</th>
<td><?php echo $ps_number; ?></td>
</tr>
<?php
}
}
A few notes:
- I have started the first number at 1001, you can change that number in the above code to another number. This is ONLY used for the first number. The next number will be calculated from there on
- The number is stored in the order and can be edited in the “Custom Fields” section of the order.
- It’s not possible to edit the next number without going into the database… Unfortunately! Normally this shouldn’t be necessary though.
Hope that helps!
Ewout
Thank you
How can I change the number into the database?
Thank you
Plugin Contributor
Ewout
(@pomegranate)
To change the number you can simply edit it on the Order page!
Changing the ‘next number’ will require you to open the database with something like phpMyAdmin.
Alternatively, you can add the following line to your theme functions.php:
update_option( 'wcpdf_next_packing_slip_number', 1 );
Then load any page on your website and remove that line from functions.php again. This will reset the ‘next number’ counter to 1.