Hi @mparsons501979,
Try adding this code snippet to your site:
/**
* Show if it's a new customer on the invoice
*/
add_action( 'wpo_wcpdf_after_order_data', 'wpo_wcpdf_profit_amount', 10, 2 );
function wpo_wcpdf_profit_amount($template_type, $order) {
if ($template_type == 'packing-slip') {
if( !empty( $user_id = $order->get_user_id() ) ){
$value = $user_id;
} else {
$value = $order->get_billing_email();
}
if( has_bought( $value ) ) {
?>
<span style="font-weight:bold;text-transform:uppercase">Returning Customer</span>
<?php
} else {
?>
<span style="font-weight:bold;text-transform:uppercase">New Customer</span>
<?php
}
}
}
function has_bought( $value = 0 ) {
if ( ! is_user_logged_in() && $value === 0 ) {
return false;
}
global $wpdb;
// Based on user ID (registered users)
if ( is_numeric( $value) ) {
$meta_key = '_customer_user';
$meta_value = $value == 0 ? (int) get_current_user_id() : (int) $value;
}
// Based on billing email (Guest users)
else {
$meta_key = '_billing_email';
$meta_value = sanitize_email( $value );
}
$paid_order_statuses = array_map( 'esc_sql', wc_get_is_paid_statuses() );
$count = $wpdb->get_var( $wpdb->prepare("
SELECT COUNT(p.ID) FROM {$wpdb->prefix}posts AS p
INNER JOIN {$wpdb->prefix}postmeta AS pm ON p.ID = pm.post_id
WHERE p.post_status IN ( 'wc-" . implode( "','wc-", $paid_order_statuses ) . "' )
AND p.post_type LIKE 'shop_order'
AND pm.meta_key = '%s'
AND pm.meta_value = %s
LIMIT 1
", $meta_key, $meta_value ) );
// Return a boolean value based on orders count
return $count > 1 ? true : false;
}
If you haven’t worked with code snippets (actions/filters) or functions.php before, read this guide: How to use filters
Let me know if it worked!