| Server IP : 104.171.130.249 / Your IP : 216.73.216.146 Web Server : nginx/1.25.5 System : Linux 0dac65491b7e 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : root ( 0) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/html/wp-content/themes/matreshka/ |
Upload File : |
<?php
/*
Template Name: Уведомления
*/
get_header();
// Check if user is logged in
if ( ! is_user_logged_in() ) {
wp_redirect( wc_get_page_permalink( 'myaccount' ) );
exit;
}
$current_user = wp_get_current_user();
?>
<!-- bread-crumb -->
<section class="bread-crumb d-none d-md-flex mt-4">
<div class="container">
<p class="montserrat-medium">
<a href="<?php echo esc_url( home_url( '/' ) ); ?>" class="text-decoration-none text-dark">Главная</a>
<span class="dot">●</span>
<a href="<?php echo esc_url( wc_get_page_permalink( 'myaccount' ) ); ?>" class="text-decoration-none text-dark">Профиль</a>
<span class="dot">●</span>
<span class="bread-crumb-product">Уведомления</span>
</p>
</div>
</section>
<!-- navigation -->
<section>
<div class="container navigation ">
<div class="d-flex w-100 align-items-center">
<a href="javascript:history.back()" class="ms-2 d-block d-md-none">
<img src="<?php echo esc_url( get_template_directory_uri() . '/assets/icons/AltArrowLeft.svg' ); ?>" alt="arrow left icon">
</a>
<h2 class="profile-title montserrat-bold mx-auto mx-md-0">Уведомления</h2>
<button class="btn ms-md-auto" id="clear-notifications-btn" onclick="clearAllNotifications()">
<img src="<?php echo esc_url( get_template_directory_uri() . '/assets/icons/Trash.svg' ); ?>" alt="Очистить историю" width="22" height="22">
</button>
</div>
</div>
</section>
<!-- section-profile-info -->
<section>
<div class="container ">
<div class="container-cart notifications-profile">
<?php
// Get user notifications from user meta
$notifications = get_user_meta( $current_user->ID, 'matreshka_notifications', true );
// If no notifications stored OR user cleared them, show demo notifications
// But only if the meta doesn't exist at all (not set yet)
if ( ! metadata_exists( 'user', $current_user->ID, 'matreshka_notifications' ) ) {
// First time user - show demo notifications
$notifications = array(
array(
'title' => 'Название акции 🔥',
'content' => 'Lorem ipsum neque tellus iaculis mus eget eget nibh fames vivamus volutpat enim cursus at massa sollicitudin morbi morbi nec congue adipiscing sed ut.',
'date' => current_time( 'timestamp' ) - DAY_IN_SECONDS,
),
array(
'title' => 'Специальное предложение для Вас! 🎁',
'content' => 'Получите скидку 15% на следующую покупку. Промокод действует до конца месяца.',
'date' => current_time( 'timestamp' ) - ( DAY_IN_SECONDS * 2 ),
),
);
} elseif ( empty( $notifications ) ) {
// User cleared notifications or has none
$notifications = array();
}
if ( ! empty( $notifications ) ) :
foreach ( $notifications as $notification ) :
$date = isset( $notification['date'] ) ? $notification['date'] : current_time( 'timestamp' );
$date_formatted = date_i18n( 'd M. H:i', $date );
// Russian month names (short)
$months_ru = array(
'Jan' => 'янв', 'Feb' => 'фев', 'Mar' => 'мар',
'Apr' => 'апр', 'May' => 'мая', 'Jun' => 'июн',
'Jul' => 'июл', 'Aug' => 'авг', 'Sep' => 'сен',
'Oct' => 'окт', 'Nov' => 'ноя', 'Dec' => 'дек'
);
foreach ( $months_ru as $en => $ru ) {
$date_formatted = str_replace( $en, $ru, $date_formatted );
}
?>
<div class="notification-profile">
<h4 class="montserrat-bold"><?php echo esc_html( $notification['title'] ); ?></h4>
<p class="montserrat-regular">
<?php echo esc_html( $notification['content'] ); ?>
</p>
<span class="montserrat-medium">
<?php echo esc_html( $date_formatted ); ?>
</span>
</div>
<?php endforeach; ?>
<?php else : ?>
<div class="text-center py-5">
<img src="<?php echo esc_url( get_template_directory_uri() . '/assets/img/notfount.png' ); ?>" alt="No notifications" class="mb-3" style="max-width: 200px;">
<p class="montserrat-medium">У вас пока нет уведомлений</p>
</div>
<?php endif; ?>
</div>
</div>
</section>
<?php if ( ! empty( $notifications ) ) : ?>
<!-- section-end -->
<section>
<div class="container ">
<div class="container-cart text-center">
<img src="<?php echo esc_url( get_template_directory_uri() . '/assets/img/Verified Check.png' ); ?>" alt="section end" class="mx-auto">
<p class="mt-3" style="color: #696969;">Это все уведомления за последние 60 дней</p>
</div>
</div>
</section>
<?php endif; ?>
<script>
function clearAllNotifications() {
if (!confirm('Вы уверены, что хотите удалить все уведомления?')) {
return;
}
const btn = document.getElementById('clear-notifications-btn');
btn.disabled = true;
fetch('<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
action: 'matreshka_clear_notifications',
nonce: '<?php echo wp_create_nonce( 'matreshka_notifications_nonce' ); ?>'
})
})
.then(response => response.json())
.then(data => {
if (data.success) {
// Reload page to show empty state
window.location.reload();
} else {
alert(data.data.message || 'Ошибка при удалении уведомлений');
btn.disabled = false;
}
})
.catch(error => {
console.error('Error:', error);
alert('Произошла ошибка. Попробуйте еще раз.');
btn.disabled = false;
});
}
</script>
<?php
get_footer();