Task 6883 | удалил лишний неиспользуемый код, разнес на отдельные файлы по их функциональному назначению
parent
c37295ba6a
commit
60bcacea61
@ -1,254 +0,0 @@ |
||||
<?php |
||||
|
||||
add_action('template_redirect', 'redirect_non_logged_in_users'); |
||||
|
||||
function redirect_non_logged_in_users() { |
||||
// URL личного кабинета (замените 'your-account-page-slug' на ваш slug) |
||||
$account_page_slug = 'my-account-3'; |
||||
$account_page_slug__2 = 'my-account'; |
||||
// Проверяем, находится ли пользователь на странице личного кабинета |
||||
if (is_page($account_page_slug) && !is_user_logged_in() || is_page($account_page_slug__2) && !is_user_logged_in() ) { |
||||
wp_redirect(home_url()); // Перенаправляем на главную страницу |
||||
exit; |
||||
} |
||||
} |
||||
|
||||
add_action('init', 'register_pets'); |
||||
function register_pets(){ |
||||
register_post_type('pets', array( |
||||
'labels' => array( |
||||
'name' => 'Питомцы', // Основное название типа записи |
||||
'singular_name' => 'Питомец', // отдельное название записи типа Book |
||||
'add_new' => 'Добавить нового', |
||||
'add_new_item' => 'Добавить нового питомца', |
||||
'edit_item' => 'Редактировать питомца', |
||||
'new_item' => 'Новый питомец', |
||||
'view_item' => 'Посмотреть питомца', |
||||
'search_items' => 'Найти питомца', |
||||
'not_found' => 'Питомцев не найдено', |
||||
'not_found_in_trash' => 'В корзине книг не найдено', |
||||
'parent_item_colon' => '', |
||||
'menu_name' => 'Питомцы' |
||||
|
||||
), |
||||
'public' => false, |
||||
'show_ui' => true, |
||||
'supports' => array('title','editor') |
||||
) ); |
||||
} |
||||
|
||||
function get_pet_card($item){ |
||||
?> |
||||
<?php |
||||
|
||||
switch (get_field('weight')){ |
||||
case ('below_1_5'): |
||||
$w = esc_html__('from 0,5 kg to 1,5 kg', 'woodmart' ); |
||||
break; |
||||
case ('1_5-3'): |
||||
$w = esc_html__('from 1.5 to 3 kg', 'woodmart' ); |
||||
break; |
||||
case ('3-5'): |
||||
$w = esc_html__('from 3 to 5 kg', 'woodmart' ); |
||||
break; |
||||
case ('5-8'): |
||||
$w = esc_html__('from 5 to 8 kg', 'woodmart' ); |
||||
break; |
||||
case ('8-11'): |
||||
$w = esc_html__('from 8 to 11 kg', 'woodmart' ); |
||||
break; |
||||
case ('11-15'): |
||||
$w = esc_html__('from 11 to 15 kg', 'woodmart' ); |
||||
break; |
||||
case ('15-20'): |
||||
$w = esc_html__('from 15 to 20 kg', 'woodmart' ); |
||||
break; |
||||
case ('20-25'): |
||||
$w = esc_html__('from 20 to 25 kg', 'woodmart' ); |
||||
break; |
||||
|
||||
|
||||
case ('25-35'): |
||||
$w = esc_html__('from 25 to 35 kg', 'woodmart' ); |
||||
break; |
||||
|
||||
|
||||
case ('more_35'): |
||||
$w = esc_html__('More than 35 kg', 'woodmart' ); |
||||
break; |
||||
|
||||
} |
||||
switch (get_field('old')){ |
||||
case ('normal'): |
||||
$old = esc_html__('Adult (from 1 year to 7 years)', 'woodmart' ); |
||||
break; |
||||
case ('old'): |
||||
$old = esc_html__('Elderly (from 7 to 12 years)', 'woodmart' ); |
||||
break; |
||||
case ('very_old'): |
||||
$old = esc_html__('Aging (12 years and older)', 'woodmart' ); |
||||
break; |
||||
case ('baby'): |
||||
$old = esc_html__('Baby (from 0 to 1 year)' ); |
||||
break; |
||||
} |
||||
|
||||
switch (get_field('activity')){ |
||||
case ('low'): |
||||
$act = esc_html__('Low', 'woodmart' ); |
||||
break; |
||||
case ('moderate'): |
||||
$act = esc_html__('Moderate', 'woodmart' ); |
||||
break; |
||||
case ('high'): |
||||
$act = esc_html__('High', 'woodmart' ); |
||||
break; |
||||
|
||||
} |
||||
?> |
||||
<div class="cabinet-card cabinet-card--green"> |
||||
<div class="cabinet-card__content"> |
||||
<div class="cabinet-card__pet"> |
||||
<div class="cabinet-card-pet__icon"> |
||||
<div class="cabinet-card-pet-icon__content"> |
||||
<img src="<?= get_template_directory_uri();?>/gp-include/assets/lk/img/pet/mini-<?php echo get_field('type', $item) ?>.png" alt="">
|
||||
</div> |
||||
</div> |
||||
|
||||
<p class="cabinet-card-pet__name"><?php echo get_the_title($item) ?></p>
|
||||
</div> |
||||
|
||||
<div class="cabinet-card__element"> |
||||
<p class="cabinet-card__label"><?php echo esc_html__('Breed', 'woodmart' ) ?>:</p>
|
||||
<p class="cabinet-card__text"><?php echo get_field('breed', $item) ?></p>
|
||||
</div> |
||||
<div class="cabinet-card__element"> |
||||
<p class="cabinet-card__label"><?php echo esc_html__('Weight', 'woodmart' ) ?>:</p>
|
||||
<p class="cabinet-card__text"><?php echo $w; ?></p>
|
||||
</div> |
||||
<?php if ($old): ?> |
||||
<div class="cabinet-card__element"> |
||||
<p class="cabinet-card__label"><?php echo esc_html__('Age', 'woodmart' ) ?>:</p>
|
||||
<p class="cabinet-card__text"><?php echo $old; ?></p>
|
||||
</div> |
||||
|
||||
<?php |
||||
else: |
||||
?> |
||||
<?
|
||||
$zero = ''; |
||||
if (intval(get_field('month', $item)) < 10){ $zero = '0'; } |
||||
?> |
||||
<div class="cabinet-card__element"> |
||||
<p class="cabinet-card__label"><?php echo esc_html__('Birhtday', 'woodmart' ) ?>:</p>
|
||||
<p class="cabinet-card__text"><?php echo get_field('day', $item) . '.' . $zero . get_field('month', $item) . '.' . get_field('year', $item); ?></p>
|
||||
</div> |
||||
<? endif; ?> |
||||
<div class="cabinet-card__element"> |
||||
<p class="cabinet-card__label"><?php echo esc_html__('Activity', 'woodmart' ) ?>:</p>
|
||||
<p class="cabinet-card__text"><?php echo $act; ?></p>
|
||||
</div> |
||||
<?php if (get_field('type', $item) == 'cat' && get_field('sterilized', $item)):?> |
||||
<div class="cabinet-card__element"> |
||||
<p class="cabinet-card__label"><?php echo esc_html__('Sterilized', 'woodmart' ) ?></p>
|
||||
|
||||
</div> |
||||
<? endif; ?> |
||||
<div class="cabinet-card__element"> |
||||
<button class="cabinet-card__button" data-edit="<?php echo get_the_ID($item); ?>">
|
||||
<?php echo esc_html__('Edit', 'woodmart' ) ?> |
||||
</button> |
||||
</div> |
||||
</div> |
||||
</div> |
||||
<?php |
||||
} |
||||
|
||||
|
||||
// Подключение скриптов и стилей |
||||
// add_action('wp_enqueue_scripts', 'enqueue_checkout_scripts'); |
||||
// function enqueue_checkout_scripts() { |
||||
// if (is_checkout()) { |
||||
// wp_enqueue_style('custom-checkout', get_template_directory_uri() . '/modules/shop/components/checkout/assets/css/checkout.css', [], '1.0.1'); |
||||
// wp_enqueue_script('custom-checkout', get_template_directory_uri() . '/modules/shop/components/checkout/assets/js/script.js', ['jquery'], '1.0.1', true); |
||||
// wp_localize_script('custom-checkout', 'wc_checkout_params', [ |
||||
// 'ajax_url' => admin_url('admin-ajax.php'), |
||||
// 'nonce' => wp_create_nonce('wc_checkout_nonce') |
||||
// ]); |
||||
// } |
||||
// } |
||||
|
||||
// // AJAX-обработчик для обновления количества |
||||
// add_action('wp_ajax_update_cart_quantity', 'update_cart_quantity_callback'); |
||||
// add_action('wp_ajax_nopriv_update_cart_quantity', 'update_cart_quantity_callback'); |
||||
// function update_cart_quantity_callback() { |
||||
// check_ajax_referer('wc_checkout_nonce', 'nonce'); |
||||
|
||||
// $cart_item_key = sanitize_text_field($_POST['cart_item_key']); |
||||
// $quantity = intval($_POST['quantity']); |
||||
|
||||
// if ($quantity > 0) { |
||||
// WC()->cart->set_quantity($cart_item_key, $quantity); |
||||
// } else { |
||||
// WC()->cart->remove_cart_item($cart_item_key); |
||||
// } |
||||
|
||||
// WC()->cart->calculate_totals(); |
||||
|
||||
// // Подготовка фрагментов |
||||
// $fragments = []; |
||||
|
||||
// // Обновление списка товаров |
||||
// ob_start(); |
||||
// wc_get_template('checkout/form-checkout.php', [], '', get_template_directory() . '/woocommerce/'); |
||||
// $fragments['.order-your__products'] = ob_get_clean(); |
||||
|
||||
// // Обновление секции итогов |
||||
// ob_start(); |
||||
// woocommerce_checkout_coupon_form(); |
||||
// woocommerce_order_review(); |
||||
// $fragments['.order-your__calculation'] = ob_get_clean(); |
||||
|
||||
// // Подготовка цен для каждого товара |
||||
// $item_prices = []; |
||||
// foreach (WC()->cart->get_cart() as $item_key => $item) { |
||||
// $item_prices[$item_key] = WC()->cart->get_product_subtotal($item['data'], $item['quantity']); |
||||
// } |
||||
|
||||
// wp_send_json_success([ |
||||
// 'fragments' => $fragments, |
||||
// 'item_prices' => $item_prices, |
||||
// 'cart_total' => WC()->cart->get_cart_total() |
||||
// ]); |
||||
// } |
||||
|
||||
// // AJAX-обработчик для удаления товара |
||||
// add_action('wp_ajax_remove_cart_item', 'remove_cart_item_callback'); |
||||
// add_action('wp_ajax_nopriv_remove_cart_item', 'remove_cart_item_callback'); |
||||
// function remove_cart_item_callback() { |
||||
// check_ajax_referer('wc_checkout_nonce', 'nonce'); |
||||
|
||||
// $cart_item_key = sanitize_text_field($_POST['cart_item_key']); |
||||
// WC()->cart->remove_cart_item($cart_item_key); |
||||
// WC()->cart->calculate_totals(); |
||||
|
||||
// // Подготовка фрагментов |
||||
// $fragments = []; |
||||
|
||||
// // Обновление списка товаров |
||||
// ob_start(); |
||||
// wc_get_template('checkout/form-checkout.php', [], '', get_template_directory() . '/woocommerce/'); |
||||
// $fragments['.order-your__products'] = ob_get_clean(); |
||||
|
||||
// // Обновление секции итогов |
||||
// ob_start(); |
||||
// woocommerce_checkout_coupon_form(); |
||||
// woocommerce_order_review(); |
||||
// $fragments['.order-your__calculation'] = ob_get_clean(); |
||||
|
||||
// wp_send_json_success([ |
||||
// 'fragments' => $fragments, |
||||
// 'cart_total' => WC()->cart->get_cart_total() |
||||
// ]); |
||||
// } |
||||
|
@ -0,0 +1,25 @@ |
||||
<?php |
||||
|
||||
add_action('init', 'register_pets'); |
||||
function register_pets(){ |
||||
register_post_type('pets', array( |
||||
'labels' => array( |
||||
'name' => 'Питомцы', // Основное название типа записи |
||||
'singular_name' => 'Питомец', // отдельное название записи типа Book |
||||
'add_new' => 'Добавить нового', |
||||
'add_new_item' => 'Добавить нового питомца', |
||||
'edit_item' => 'Редактировать питомца', |
||||
'new_item' => 'Новый питомец', |
||||
'view_item' => 'Посмотреть питомца', |
||||
'search_items' => 'Найти питомца', |
||||
'not_found' => 'Питомцев не найдено', |
||||
'not_found_in_trash' => 'В корзине книг не найдено', |
||||
'parent_item_colon' => '', |
||||
'menu_name' => 'Питомцы' |
||||
|
||||
), |
||||
'public' => false, |
||||
'show_ui' => true, |
||||
'supports' => array('title','editor') |
||||
) ); |
||||
} |
@ -0,0 +1,16 @@ |
||||
<?php |
||||
|
||||
add_action('template_redirect', 'redirect_non_logged_in_users'); |
||||
|
||||
function redirect_non_logged_in_users() { |
||||
// URL личного кабинета (замените 'your-account-page-slug' на ваш slug) |
||||
$account_page_slug = 'my-account-3'; |
||||
$account_page_slug__2 = 'my-account'; |
||||
// Проверяем, находится ли пользователь на странице личного кабинета |
||||
if (is_page($account_page_slug) && !is_user_logged_in() || is_page($account_page_slug__2) && !is_user_logged_in() ) { |
||||
wp_redirect(home_url()); // Перенаправляем на главную страницу |
||||
exit; |
||||
} |
||||
} |
||||
|
||||
|
Loading…
Reference in new issue