Skip to content

Instantly share code, notes, and snippets.

@fburatti
Created March 11, 2016 18:56
Show Gist options
  • Save fburatti/f928729a9a8ddb2244fd to your computer and use it in GitHub Desktop.
Save fburatti/f928729a9a8ddb2244fd to your computer and use it in GitHub Desktop.
<?php
add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_receipt_number', 10, 2 );
function wpo_wcpdf_receipt_number ($template_type, $order) {
global $wpo_wcpdf;
if ($template_type == 'receipt') {
// get number from order
$receipt_number = get_post_meta( $order->id, 'Receipt Number', true );
// get number from database if no number present yet
if (empty($receipt_number)) {
$receipt_number = get_option( 'wcpdf_next_receipt_number', 1001 ); // change 1001 to define the first number
// store number in order
update_post_meta($order->id, 'Receipt Number', $receipt_number);
// increase Receipt number in database
update_option( 'wcpdf_next_receipt_number', $receipt_number+1 );
}
?>
<tr class="receipt-number">
<th>Receipt Number:</th>
<td><?php echo $receipt_number; ?></td>
</tr>
<?php
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment