add_action( 'woocommerce_after_add_to_cart_button', 'dmm_estimated_delivery' );
function dmm_estimated_delivery() {
date_default_timezone_set( 'Europe/Rome' );
// Calcola la data di consegna in base al giorno dell'ordine
$current_date = strtotime('today');
$day_of_week = date('N', $current_date);
if ($day_of_week == 1) { // Lunedì
$delivery_min = strtotime('+2 days', $current_date);
$delivery_max = strtotime('+3 days', $current_date);
} elseif ($day_of_week == 2) { // Martedì
$delivery_min = strtotime('+2 days', $current_date);
$delivery_max = strtotime('+3 days', $current_date);
} elseif ($day_of_week == 3) { // Mercoledì
$delivery_min = strtotime('+2 days', $current_date);
$delivery_max = strtotime('+5 days', $current_date);
} elseif ($day_of_week == 4) { // Giovedì
$delivery_min = strtotime('+4 days', $current_date);
$delivery_max = strtotime('+5 days', $current_date);
} elseif ($day_of_week == 5) { // Venerdì
$delivery_min = strtotime('+4 days', $current_date);
$delivery_max = strtotime('+5 days', $current_date);
} elseif ($day_of_week == 6) { // Sabato
$delivery_min = strtotime('+3 days', $current_date);
$delivery_max = strtotime('+4 days', $current_date);
} elseif ($day_of_week == 7) { // Domenica
$delivery_min = strtotime('+2 days', $current_date);
$delivery_max = strtotime('+3 days', $current_date);
}
// Formattazione delle date nel formato richiesto
$del_day_min = date_i18n( 'l j M', $delivery_min );
$del_day_max = date_i18n( 'l j M', $delivery_max );
// Converti il testo in minuscolo
$del_day_min = strtolower($del_day_min);
$del_day_max = strtolower($del_day_max);
echo '<div class="estimate-delivery">';
echo '<i class="fa-solid fa-truck-fast"></i>';
echo '<span> Ricevilo tra </span>';
echo '<span><strong>' . $del_day_min . '</strong></span>';
echo '<span> e </span>';
echo '<span><strong>' . $del_day_max . '</strong></span>';
echo '</div>';
}
Copia il codice nel file functions.php del tuo tema child attivo o utilizza il plugin Code Snippets.