Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save FrancoStino/2d4686253b07f44b1c08d10388b6c270 to your computer and use it in GitHub Desktop.
Save FrancoStino/2d4686253b07f44b1c08d10388b6c270 to your computer and use it in GitHub Desktop.
Send an email when added order note containing tracking shipping code (GLS) - Woocommerce
<?php
// Send an email when added order note containing tracking code (GLS)
add_action( 'woocommerce_order_note_added', 'woocommerce_order_notes_notification', 10, 2);
function woocommerce_order_notes_notification( $note_id, $order ) {
// recupera l'oggetto nota e l'ID dell'ordine associato
$note = wc_get_order_note( $note_id );
$order_id = $note->order_id;
// recupera la stringa specifica da cercare nelle note dell'ordine
$stringa_tracking = 'BA';
$stringa_GLS = 'GLS';
// verifica se la nota contiene la stringa specifica
if ( strpos( $note->content, $stringa_tracking ) !== false && strpos( $note->content, $stringa_GLS ) !== false ) {
$tracking = strstr($note->content, "BA");
$link_GLS = 'https://gls-group.com/IT/it/servizi-online/ricerca-spedizioni.html?match=' . $tracking . '&type=NAT';
$to = $order->get_billing_email();
$subject = "Codice di tracciamento del pacco - Ordine: #" . $order->get_id();
$message = 'Ciao ' . $order->get_billing_first_name() . ',';
$message.= '<br> Il tuo numero di tracciamento per monitorare il pacco è: <b><a href=' . $link_GLS . ' target="_blank">' . $tracking . '</a></b>';
$message.= '<a style="font-family: Helvetica Neue,Helvetica,Roboto,Arial,sans-serif; text-decoration:none; background-color:#6eb356; border-radius:50px; color:#ffffff; font-size:16px; padding:10px 25px; font-weight:600; display:inline-block; margin-top:40px;" href=' . $link_GLS . ' target="_blank">TRACCIA IL TUO PACCO</a>';
$headers = "Content-Type: text/htmlrn";
$mailer = WC()->mailer();
$mailer->send($to, $subject, $mailer->wrap_message( $subject, $message ), $headers);
}
}
// Rename "completed" Order Status to "shipped"
add_filter( 'wc_order_statuses', 'bbloomer_rename_completed_order_status' );
function bbloomer_rename_completed_order_status( $statuses ) {
$statuses['wc-completed'] = 'Spedito';
return $statuses;
}
add_filter( 'woocommerce_register_shop_order_post_statuses', 'bbloomer_rename_completed_order_status_counter' );
function bbloomer_rename_completed_order_status_counter( $statuses ) {
$statuses['wc-completed']['label_count'] = _n_noop( 'Spedito <span class="count">(%s)</span>', 'Spedito <span class="count">(%s)</span>', 'woocommerce' );
return $statuses;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment