I’ve got some code working which shows a message at the top of the packing slips if we have a new customer.
However, it’s showing the message for all orders, so I’ve figured my code isn’t getting the right info from WooCommerce to confirm if the customer has previously placed an order.
We’re using HPOS too.
function action_wpo_wcpdf_after_document_label( $wpo_wcpdf_export_template_type, $order ) {
if ('packing-slip' != $wpo_wcpdf_export_template_type) { return; }
$billing_email = $order->get_billing_email();
if (!$billing_email) {
return;
}
$customer_orders = get_posts( array(
'numberposts' => -1,
'exclude' => array($order->get_id()),
'meta_key' => '_billing_email',
'meta_value' => $billing_email,
'post_type' => wc_get_order_types(),
'post_status' => array_keys( wc_get_order_statuses() ),
) );
if (empty($customer_orders)) { print "n" . '<p class="form-field form-field-wide" style="font-weight: bold;margin-top: -60px;border: 1px solid;width: 90px;padding: 3px 10px 5px 10px;line-height: 1;text-align: center;">New Customer</p>' . "n"; return; }
else { print "n" . '<p class="form-field form-field-wide" style="font-weight: bold;margin-top: -60px;border: 1px solid;width: 90px;padding: 3px 10px 5px 10px;line-height: 1;text-align: center;">Existing Customer</p>' . "n"; return; }
return;
}
add_action( 'wpo_wcpdf_after_document_label', 'action_wpo_wcpdf_after_document_label', 10, 2 );