Task 5453 | wif: разнес функции админки в отдельный файл

pull/36/head
parent 1c2dedb195
commit 9423d3a89a
  1. 1
      wp-content/themes/cosmopet/functions.php
  2. 72
      wp-content/themes/cosmopet/global-functions/core-functions.php
  3. 101
      wp-content/themes/cosmopet/temp-functions/custom-admin-panel-logic.php
  4. 77
      wp-content/themes/cosmopet/temp-functions/woocommerce-logic.php

@ -14,6 +14,7 @@ require_once __DIR__ . '/temp-functions/ajax-logic.php';
require_once __DIR__ . '/temp-functions/shortcodes-logic.php';
require_once __DIR__ . '/temp-functions/blog-logic.php';
require_once __DIR__ . '/temp-functions/filters-logic.php';
require_once __DIR__ . '/temp-functions/custom-admin-panel-logic.php';
// include_module('forms');
// include_module('shop');

@ -3,14 +3,14 @@
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;
}
// 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');
@ -135,40 +135,32 @@ case ('high'):
<?php
else:
?>
<?php
$zero = '';
if (intval(get_field('month', $item)) < 10){
$zero = '0';
}
<?
$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>
<?php
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>
<?php
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>
<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
}

@ -0,0 +1,101 @@
<?
// woocommerce_product_options_pricing - // после цен
/**
* Start: Добавление табов и полей в стандартной форме редактирования товара Woocommerce
*/
/* Вывод пользовательского поля */
add_action('woocommerce_product_data_panels', function () {
global $post;
$composition = get_post_meta($post->ID, '_composition', true);
echo '<div id="composition_product_data" class="panel woocommerce_options_panel">';
woocommerce_wp_textarea_input([
'id' => '_composition',
'label' => 'Состав',
'desc_tip' => true,
'description' => 'Введите состав товара',
'value' => $composition
]);
echo '</div>';
});
/* Вывод пользовательских табов */
// add_action('woocommerce_product_data_panels', function () {
// global $post;
// $feeding = get_post_meta($post->ID, '_feeding_recommendations', true);
// echo '<div id="feeding_product_data" class="panel woocommerce_options_panel">';
// woocommerce_wp_textarea_input([
// 'id' => '_feeding_recommendations',
// 'label' => 'Рекомендации по кормлению',
// 'desc_tip' => true,
// 'description' => 'Введите рекомендации по кормлению',
// 'value' => $feeding
// ]);
// echo '</div>';
// });
// add_action('woocommerce_product_data_panels', function () {
// global $post;
// $important = get_post_meta($post->ID, '_important', true);
// echo '<div id="important_product_data" class="panel woocommerce_options_panel">';
// woocommerce_wp_textarea_input([
// 'id' => '_important',
// 'label' => 'Важно',
// 'desc_tip' => true,
// 'description' => 'Введите важную информацию',
// 'value' => $important
// ]);
// echo '</div>';
// });
// woocommerce_product_options_inventory_product_data ]
add_filter('woocommerce_product_data_tabs', function ($tabs) {
$tabs['composition_tab'] = array(
'label' => 'Состав',
'target' => 'composition_product_data',
'class' => array('composition_tab'),
'priority' => 60,
);
// shipping_product_data
// shipping_options
// shipping_tab
// $tabs['feeding_tab'] = array(
// 'label' => 'Рекомендации по кормлению',
// 'target' => 'feeding_product_data',
// 'class' => array('feeding_tab'),
// 'priority' => 61,
// );
// $tabs['important_tab'] = array(
// 'label' => 'Важно',
// 'target' => 'important_product_data',
// 'class' => array('important_tab'),
// 'priority' => 62,
// );
return $tabs;
});
/* сохраненение кастомных полей */
add_action('woocommerce_process_product_meta', function ($post_id) {
if (isset($_POST['_composition'])) {
update_post_meta($post_id, '_composition', sanitize_textarea_field($_POST['_composition']));
}
// if (isset($_POST['_feeding_recommendations'])) {
// update_post_meta($post_id, '_feeding_recommendations', sanitize_textarea_field($_POST['_feeding_recommendations']));
// }
// if (isset($_POST['_important'])) {
// update_post_meta($post_id, '_important', sanitize_textarea_field($_POST['_important']));
// }
});
/**
* End: Добавление табов и полей в стандартной форме редактирования товара Woocommerce
*/

@ -148,84 +148,7 @@ function get_collection_siblings ($term) {
add_filter( 'woocommerce_price_trim_zeros', '__return_true' );
add_filter('woocommerce_product_data_tabs', function($tabs) {
$tabs['composition_tab'] = array(
'label' => 'Состав',
'target' => 'composition_product_data',
'class' => array('composition_tab'),
'priority' => 60,
);
$tabs['feeding_tab'] = array(
'label' => 'Рекомендации по кормлению',
'target' => 'feeding_product_data',
'class' => array('feeding_tab'),
'priority' => 61,
);
$tabs['important_tab'] = array(
'label' => 'Важно',
'target' => 'important_product_data',
'class' => array('important_tab'),
'priority' => 62,
);
return $tabs;
});
add_action('woocommerce_product_data_panels', function() {
global $post;
$composition = get_post_meta($post->ID, '_composition', true);
echo '<div id="composition_product_data" class="panel woocommerce_options_panel">';
woocommerce_wp_textarea_input([
'id' => '_composition',
'label' => 'Состав',
'desc_tip' => true,
'description' => 'Введите состав товара',
'value' => $composition
]);
echo '</div>';
});
add_action('woocommerce_product_data_panels', function() {
global $post;
$feeding = get_post_meta($post->ID, '_feeding_recommendations', true);
echo '<div id="feeding_product_data" class="panel woocommerce_options_panel">';
woocommerce_wp_textarea_input([
'id' => '_feeding_recommendations',
'label' => 'Рекомендации по кормлению',
'desc_tip' => true,
'description' => 'Введите рекомендации по кормлению',
'value' => $feeding
]);
echo '</div>';
});
add_action('woocommerce_product_data_panels', function() {
global $post;
$important = get_post_meta($post->ID, '_important', true);
echo '<div id="important_product_data" class="panel woocommerce_options_panel">';
woocommerce_wp_textarea_input([
'id' => '_important',
'label' => 'Важно',
'desc_tip' => true,
'description' => 'Введите важную информацию',
'value' => $important
]);
echo '</div>';
});
add_action('woocommerce_process_product_meta', function($post_id) {
if (isset($_POST['_composition'])) {
update_post_meta($post_id, '_composition', sanitize_textarea_field($_POST['_composition']));
}
if (isset($_POST['_feeding_recommendations'])) {
update_post_meta($post_id, '_feeding_recommendations', sanitize_textarea_field($_POST['_feeding_recommendations']));
}
if (isset($_POST['_important'])) {
update_post_meta($post_id, '_important', sanitize_textarea_field($_POST['_important']));
}
});
// Добавление поля для выбора рекомендуемых товаров
function register_recommended_products_acf_field() {
if (function_exists('acf_add_local_field_group')) {

Loading…
Cancel
Save