Untitled
unknown
plain_text
2 years ago
2.2 kB
7
Indexable
// Target specific email notification
if ( $email->id == 'new_order' ) {
// Get email and phone
$customer_email = $order->get_billing_email();
$customer_phone = $order->get_billing_phone();
// NOT empty
if ( ! empty( $customer_email ) ) {
// Get orders from customer by email and statuses
$orders_by_customer_email = wc_get_orders( array(
'customer' => $customer_email,
'status' => array( 'wc-on-hold','wc-processing','wc-completed','wc-cancelled','col-shipping-init' ),
'limit' => -1,
'return' => 'ids'
));
// Get orders from customer by phone and statuses
$orders_by_customer_phone = wc_get_orders( array(
'billing_phone' => $customer_phone,
'status' => array( 'wc-on-hold','wc-processing','wc-completed','wc-cancelled','col-shipping-init' ),
'limit' => -1,
'return' => 'ids'
));
// Merge the two arrays and remove duplicates
$orders_by_customer = array_unique( array_merge( $orders_by_customer_email, $orders_by_customer_phone ) );
// When new customer
if ( count( $orders_by_customer ) == 1 ) {
$customer_type = 'Nou';
} else {
$customer_type = 'Recurent';
}
// Output
// echo '' . sprintf( __( '<p style="color:#d9a09e;font-size:14px;"><b>Client:</b> %s</p><p style="color:#000;font-size:14px;"><b>Email:</b> %s</p><p style="color:#000;font-size:14px;"><b>Telefon:</b> %s</p><p style="color:#d9a09e;font-size:14px;"><b>Total comenzi:</b> %d</p>', 'woocommerce' ), $customer_type, $customer_email, $customer_phone, count( $orders_by_customer ) ) . '';
echo '' . sprintf( __( '<p style="color:#d9a09e;font-size:14px;"><b>Client:</b> %s</p><p style="color:#d9a09e;font-size:14px;"><b>Total comenzi:</b> %d</p><p style="color:#000;font-size:14px;"><b>Telefon:</b> %s</p>', 'woocommerce' ), $customer_type, count( $orders_by_customer ), $customer_phone ) . '';
}
}
}Editor is loading...