jQuery(function($) {
// Цепляемся за событие adding_to_cart
$(document.body).on('adding_to_cart', function(event, button) {
// Выцепляем инициатора события (ссылка/кнопка)
var $btn = $(button[0]);
// Пытаемся найти в вёрстке название товара и количество
var product_title = $btn.parents('li.product').find('.woocommerce-loop-product__title').text();
var product_qty = $btn.parents('li.product').find('.input-text.qty.text').val();
if (product_title && product_qty) {
// Формируем шаблон попапа
var tpl = '';
tpl += '<p>' + product_qty + ' шт. товара "' + product_title + '" добавлено в корзину</p>';
tpl += '<div>';
tpl += '<a class="button" onclick="jQuery.unblockUI();">Продолжить</a>';
tpl += '<a href="/shop/cart/" class="button alt">Оформить</a>';
tpl += '</div>';
// Выводим шаблон в модальное окно.
// Используем blockUI из WooCommerce
$.blockUI({
message: tpl,
timeout: 4000,
css: {
width: '300px',
border: 0,
padding: 30
}
});
}
});
});
add_filter( 'the_content', 'wpse_ad_content' );
function wpse_ad_content( $content ) {
if( !is_single() )
return $content;
// Массив с номерами абзацев, после которых нужно вставить рекламу
$paragraphsAfter = array(3, 6, 9);
// Массив с кодами рекламы для каждого абзаца
$ads = array(
'<div>Код рекламы для абзаца 3</div>',
'<div>Код рекламы для абзаца 6</div>',
'<div>Код рекламы для абзаца 9</div>'
);
$content = explode ( "</p>", $content );
$new_content = '';
$count = count($content);
for ( $i = 0; $i < $count; $i ++ ) {
$new_content .= $content[$i] . "</p>";
// Проверяем, нужно ли вставлять рекламу после текущего абзаца
if (in_array($i+1, $paragraphsAfter)) {
$adIndex = array_search($i+1, $paragraphsAfter);
if ($adIndex !== false && isset($ads[$adIndex])) {
$new_content .= $ads[$adIndex];
}
}
}
return $new_content;
}
if (('' !== $user_ID) && ( current_user_can('manage_options') || current_user_can('editor') )) {
$now = new DateTime();
$nothing = '';
$date_str = get_the_author_meta( '_birthday', $user_id ); // получаем дату рождения как строку
if ( empty( $date_str ) ) {
$age_str = $nothing; // если дата рождения не указана, возвращаем пустую строку
} else {
$date = new DateTime( $date_str ); // преобразуем дату рождения в объект DateTime
$diff = $now->diff( $date ); // вычисляем разницу между датами
$age_str = $diff->y; // получаем количество полных лет
}
?>
<input type="text" name="_age" id="_age" placeholder="Возраст" value="<?php echo $age_str; ?>">
function delshipping_calc_in_cart( $show_shipping ) {
if( is_cart() ) {
return false;
}
return $show_shipping;
}
add_filter( 'woocommerce_cart_ready_to_calc_shipping', 'delshipping_calc_in_cart', 99 );