Custom WooCommerce theme for orgsteklo.ru including: - Product catalog with category/subcategory hierarchy - Custom checkout with delivery calculation - Price calculator - Admin settings panel - Search functionality - User account pages
289 lines
16 KiB
PHP
289 lines
16 KiB
PHP
<?php get_header(); ?>
|
||
<?php if (is_product_category() || is_product() || is_search()): ?>
|
||
<main>
|
||
<nav class="breadcumbs container">
|
||
<ul>
|
||
<li><a href="<?php echo home_url(); ?>">Главная</a></li>
|
||
<li><p class="breadcumbs-separator">/</p></li>
|
||
<?php
|
||
if (is_search()) {
|
||
echo '<li><a href="/catalog">Каталог</a></li>';
|
||
echo '<li><p class="breadcumbs-separator">/</p></li>';
|
||
echo '<li><p>Результаты поиска: ' . esc_html( get_search_query() ) . '</p></li>';
|
||
}
|
||
elseif (is_shop()) {
|
||
echo '<li><p>Каталог</p></li>';
|
||
}
|
||
elseif (is_product_category()) {
|
||
$term = get_queried_object();
|
||
$ancestors = get_ancestors($term->term_id, 'product_cat');
|
||
echo '<li><a href="/catalog">Каталог</a></li>';
|
||
echo '<li><p class="breadcumbs-separator">/</p></li>';
|
||
if (!empty($ancestors)) {
|
||
$ancestors = array_reverse($ancestors);
|
||
foreach ($ancestors as $ancestor_id) {
|
||
$ancestor = get_term($ancestor_id, 'product_cat');
|
||
echo '<li><a href="' . esc_url(get_term_link($ancestor)) . '">' . esc_html($ancestor->name) . '</a></li>';
|
||
echo '<li><p class="breadcumbs-separator">/</p></li>';
|
||
}
|
||
}
|
||
echo '<li><p>' . esc_html($term->name) . '</p></li>';
|
||
}
|
||
?>
|
||
</ul>
|
||
</nav>
|
||
|
||
<section class="catalog_page">
|
||
<div class="catalog_page-container container">
|
||
<div class="catalog_page-menu">
|
||
<h3>Каталог</h3>
|
||
<div class="catalog_page-menu__col">
|
||
<?php
|
||
function render_product_categories_menu2($parent_id = 0, $current_cat_id = null)
|
||
{
|
||
if (!$current_cat_id && is_product_category()) {
|
||
$current_cat = get_queried_object();
|
||
$current_cat_id = $current_cat->term_id;
|
||
}
|
||
$exclude_term = get_term_by('name', 'Misc', 'product_cat');
|
||
$exclude_id = $exclude_term ? $exclude_term->term_id : 0;
|
||
$args = array(
|
||
'taxonomy' => 'product_cat',
|
||
'hide_empty' => false,
|
||
'parent' => $parent_id,
|
||
'exclude' => array($exclude_id),
|
||
'orderby' => 'menu_order',
|
||
'order' => 'ASC',
|
||
);
|
||
$categories = get_terms($args);
|
||
foreach ($categories as $category) {
|
||
$children = get_terms(array(
|
||
'taxonomy' => 'product_cat',
|
||
'hide_empty' => false,
|
||
'parent' => $category->term_id,
|
||
));
|
||
$has_children = !empty($children);
|
||
$is_active = ($category->term_id == $current_cat_id) || term_is_ancestor_of($category->term_id, $current_cat_id, 'product_cat');
|
||
echo '<div class="catalog_page-menu__item' . ($is_active ? ' active' : '') . '">';
|
||
echo '<div class="catalog_page-menu__item-button">';
|
||
echo '<a href="' . get_term_link($category) . '" class="catalog_page-menu__item-button__img">';
|
||
$icon = get_field('category_icon', 'product_cat_' . $category->term_id);
|
||
$icon_url = $icon ? $icon['url'] : get_template_directory_uri() . '/assets/images/catalog_page-menu__item-button__img.png';
|
||
echo '<img src="' . esc_url($icon_url) . '" alt="">';
|
||
echo '</a>';
|
||
echo '<div class="catalog_page-menu__item-row">';
|
||
echo '<a href="' . get_term_link($category) . '">' . esc_html($category->name) . '</a>';
|
||
if ($has_children) {
|
||
echo '<button class="catalog_page-menu__item-button__icon">';
|
||
echo '<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.96012 4.08984H5.84512H3.04012C2.56012 4.08984 2.32012 4.66984 2.66012 5.00984L5.25012 7.59984C5.66512 8.01484 6.34012 8.01484 6.75512 7.59984L7.74012 6.61484L9.34512 5.00984C9.68012 4.66984 9.44012 4.08984 8.96012 4.08984Z" fill="black"/></svg>';
|
||
echo '</button>';
|
||
}
|
||
echo '</div>';
|
||
echo '</div>';
|
||
if ($has_children) {
|
||
echo '<div class="catalog_page-menu__item-content">';
|
||
foreach ($children as $child) {
|
||
$grandchildren = get_terms(array(
|
||
'taxonomy' => 'product_cat',
|
||
'hide_empty' => false,
|
||
'parent' => $child->term_id,
|
||
));
|
||
$has_grandchildren = !empty($grandchildren);
|
||
$is_child_active = ($child->term_id == $current_cat_id) || term_is_ancestor_of($child->term_id, $current_cat_id, 'product_cat');
|
||
echo '<div class="catalog_page-menu__item-content-item' . ($is_child_active ? ' active' : '') . '">';
|
||
echo '<div class="catalog_page-menu__item-content-item-row">';
|
||
echo '<a href="' . get_term_link($child) . '">' . esc_html($child->name) . '</a>';
|
||
if ($has_grandchildren) {
|
||
echo '<button class="catalog_page-menu__item-content-item-icon">';
|
||
echo '<svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.96012 4.08984H5.84512H3.04012C2.56012 4.08984 2.32012 4.66984 2.66012 5.00984L5.25012 7.59984C5.66512 8.01484 6.34012 8.01484 6.75512 7.59984L7.74012 6.61484L9.34512 5.00984C9.68012 4.66984 9.44012 4.08984 8.96012 4.08984Z" fill="black"/></svg>';
|
||
echo '</button>';
|
||
}
|
||
echo '</div>';
|
||
if ($has_grandchildren) {
|
||
echo '<div class="catalog_page-menu__item-content-item-content">';
|
||
foreach ($grandchildren as $grandchild) {
|
||
$is_grand_active = $grandchild->term_id == $current_cat_id;
|
||
echo '<a href="' . get_term_link($grandchild) . '"' . ($is_grand_active ? ' class="active"' : '') . '>';
|
||
echo esc_html($grandchild->name) . '</a>';
|
||
}
|
||
echo '</div>';
|
||
}
|
||
echo '</div>';
|
||
}
|
||
echo '</div>';
|
||
}
|
||
echo '</div>';
|
||
}
|
||
}
|
||
?>
|
||
<?php render_product_categories_menu2(); ?>
|
||
</div>
|
||
</div>
|
||
<?php
|
||
$current_category = get_queried_object();
|
||
$child_categories = array();
|
||
|
||
if ( ! is_search() && ! is_shop() && $current_category && isset( $current_category->term_id ) ) {
|
||
$child_categories = get_terms(array(
|
||
'taxonomy' => 'product_cat',
|
||
'parent' => $current_category->term_id,
|
||
'hide_empty' => false,
|
||
));
|
||
}
|
||
|
||
if ( !empty($child_categories) ) {
|
||
// Только подкатегории, без товаров в этой категории
|
||
?>
|
||
<div class="catalog_page-main">
|
||
<h1><?php echo woocommerce_page_title(); ?></h1>
|
||
<div class="catalog_page-col">
|
||
<?php
|
||
foreach ($child_categories as $child_category) {
|
||
$thumbnail_id = get_term_meta($child_category->term_id, 'thumbnail_id', true);
|
||
$image_url = wp_get_attachment_url($thumbnail_id);
|
||
$description = term_description($child_category->term_id, 'product_cat');
|
||
echo '<div class="catalog_page-item">';
|
||
if($image_url) {
|
||
echo '<a href="' . esc_url(get_term_link($child_category)) . '" class="catalog_page-item__img">';
|
||
echo '<img src="' . esc_url($image_url) . '" alt="' . esc_attr($child_category->name) . '">';
|
||
echo '</a>';
|
||
}
|
||
echo '<div class="catalog_page-item__main">';
|
||
echo '<a href="' . esc_url(get_term_link($child_category)) . '" class="catalog_page-item__title">' . esc_html($child_category->name) . '</a>';
|
||
if($description) {
|
||
echo '<p>' . $description . '</p>';
|
||
}
|
||
echo '<a href="' . esc_url(get_term_link($child_category)) . '" class="link-more">Перейти в раздел<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M14.9997 10C14.9956 9.56159 14.819 9.14243 14.508 8.83335L10.933 5.25002C10.7769 5.09481 10.5657 5.00769 10.3455 5.00769C10.1254 5.00769 9.91414 5.09481 9.75801 5.25002C9.6799 5.32749 9.61791 5.41965 9.5756 5.5212C9.53329 5.62275 9.51151 5.73167 9.51151 5.84168C9.51151 5.95169 9.53329 6.06061 9.5756 6.16216C9.61791 6.26371 9.6799 6.35588 9.75801 6.43335L12.4997 9.16668H4.16634C3.94533 9.16668 3.73337 9.25448 3.57709 9.41076C3.42081 9.56704 3.33301 9.779 3.33301 10C3.33301 10.221 3.42081 10.433 3.57709 10.5893C3.73337 10.7455 3.94533 10.8333 4.16634 10.8333H12.4997L9.75801 13.575C9.60109 13.7308 9.51249 13.9426 9.51171 14.1637C9.51093 14.3849 9.59803 14.5973 9.75384 14.7542C9.90966 14.9111 10.1214 14.9997 10.3426 15.0005C10.5637 15.0013 10.7761 14.9142 10.933 14.7583L14.508 11.175C14.821 10.8639 14.9978 10.4413 14.9997 10Z" fill="#02ADEF"></path></svg></a>';
|
||
echo '</div>';
|
||
echo '</div>';
|
||
}
|
||
?>
|
||
</div>
|
||
</div>
|
||
<?php } else { ?>
|
||
<div class="catalog_page-main">
|
||
<div class="catalog_page-header">
|
||
<h1><?php echo is_search() ? 'Результаты поиска: ' . esc_html( get_search_query() ) : woocommerce_page_title(); ?></h1>
|
||
<div class="catalog_page-view-toggle">
|
||
<button class="catalog_page-view-btn" data-view="compact" title="Компактный вид">
|
||
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="1" width="7.5" height="7.5" rx="1.5" stroke="currentColor" stroke-width="1.5"/><rect x="11.5" y="1" width="7.5" height="7.5" rx="1.5" stroke="currentColor" stroke-width="1.5"/><rect x="1" y="11.5" width="7.5" height="7.5" rx="1.5" stroke="currentColor" stroke-width="1.5"/><rect x="11.5" y="11.5" width="7.5" height="7.5" rx="1.5" stroke="currentColor" stroke-width="1.5"/></svg>
|
||
</button>
|
||
<button class="catalog_page-view-btn" data-view="extended" title="Подробный вид">
|
||
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><rect x="1" y="1" width="18" height="3.5" rx="1" stroke="currentColor" stroke-width="1.5"/><rect x="1" y="8.25" width="18" height="3.5" rx="1" stroke="currentColor" stroke-width="1.5"/><rect x="1" y="15.5" width="18" height="3.5" rx="1" stroke="currentColor" stroke-width="1.5"/></svg>
|
||
</button>
|
||
</div>
|
||
</div>
|
||
<div class="catalog_page-products catalog_page-products__wrapper">
|
||
<?php
|
||
if (woocommerce_product_loop()) {
|
||
echo '<div class="catalog_page-products__grid">';
|
||
woocommerce_product_loop_start();
|
||
if (wc_get_loop_prop('total')) {
|
||
while (have_posts()) {
|
||
the_post();
|
||
wc_get_template_part('content', 'product');
|
||
}
|
||
}
|
||
woocommerce_product_loop_end();
|
||
echo '</div>';
|
||
|
||
echo '<div class="catalog_page-products__bottom">';
|
||
$current_per_page = isset($_GET['per_page']) ? sanitize_text_field($_GET['per_page']) : '12';
|
||
$current_label = ($current_per_page === 'all') ? 'Все' : intval($current_per_page);
|
||
$check_svg = '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M7.99998 1.33325C4.32665 1.33325 1.33331 4.32659 1.33331 7.99992C1.33331 11.6733 4.32665 14.6666 7.99998 14.6666C11.6733 14.6666 14.6666 11.6733 14.6666 7.99992C14.6666 4.32659 11.6733 1.33325 7.99998 1.33325ZM11.1866 6.46659L7.40665 10.2466C7.31331 10.3399 7.18665 10.3933 7.05331 10.3933C6.91998 10.3933 6.79331 10.3399 6.69998 10.2466L4.81331 8.35992C4.61998 8.16659 4.61998 7.84659 4.81331 7.65325C5.00665 7.45992 5.32665 7.45992 5.51998 7.65325L7.05331 9.18659L10.48 5.75992C10.6733 5.56659 10.9933 5.56659 11.1866 5.75992C11.38 5.95325 11.38 6.26659 11.1866 6.46659Z" fill="#02ADEF"/></svg>';
|
||
$per_page_options = array('12', '24', '48', 'all');
|
||
$per_page_labels = array('12' => '12', '24' => '24', '48' => '48', 'all' => 'Все');
|
||
echo '<div class="catalog_page-count"><p>Количество товаров на странице:</p>';
|
||
echo '<button class="catalog_page-count__button"><p>' . esc_html($current_label) . '</p><svg width="12" height="12" viewBox="0 0 12 12" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M8.96 4.09009H5.845H3.04C2.56 4.09009 2.32 4.67009 2.66 5.01009L5.25 7.60009C5.665 8.01509 6.34 8.01509 6.755 7.60009L7.74 6.61509L9.345 5.01009C9.68 4.67009 9.44 4.09009 8.96 4.09009Z" fill="#808080"/></svg></button>';
|
||
echo '<div class="catalog_page-count__content">';
|
||
foreach ($per_page_options as $opt) {
|
||
$is_active = ($opt === $current_per_page) ? ' active' : '';
|
||
echo '<button class="catalog_page-count__content-button' . $is_active . '"><p>' . esc_html($per_page_labels[$opt]) . '</p>' . $check_svg . '</button>';
|
||
}
|
||
echo '</div></div>';
|
||
echo '<div class="catalog_page-pagination">';
|
||
echo '<div class="catalog_page-pagination__row">';
|
||
the_posts_pagination(array(
|
||
'prev_text' => '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M10.0601 13.28L5.71339 8.9333C5.20006 8.41997 5.20006 7.57997 5.71339 7.06664L10.0601 2.71997" stroke="#02ADEF" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/></svg>', // SVG для стрелки назад
|
||
'next_text' => '<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M5.93994 13.28L10.2866 8.9333C10.7999 8.41997 10.7999 7.57997 10.2866 7.06664L5.93994 2.71997" stroke="#02ADEF" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/></svg>', // SVG для стрелки вперед
|
||
'before_page_number' => '<span class="catalog_page-pagination-item">',
|
||
'after_page_number' => '</span>',
|
||
));
|
||
echo '</div>';
|
||
global $wp_query;
|
||
$total_products = $wp_query->found_posts;
|
||
echo '<p>' . $wp_query->post_count . ' товаров <span>из ' . $total_products . '</span></p>';
|
||
echo '</div>';
|
||
|
||
// Счетчик товаров
|
||
|
||
|
||
echo '</div>';
|
||
|
||
do_action('woocommerce_after_shop_loop');
|
||
} else {
|
||
do_action('woocommerce_no_products_found');
|
||
}
|
||
?>
|
||
</div>
|
||
</div>
|
||
<?php
|
||
}
|
||
?>
|
||
</div>
|
||
</section>
|
||
<?php get_template_part( 'blocks/block', 'consult' ); ?>
|
||
</main>
|
||
<?php get_footer(); ?>
|
||
<?php else: ?>
|
||
<main>
|
||
<nav class="breadcumbs container">
|
||
<ul>
|
||
<li><a href="/">Главная</a></li>
|
||
<li><p class="breadcumbs-separator">/</p></li>
|
||
<li><p><?php echo wp_title(''); ?></p></li>
|
||
</ul>
|
||
</nav>
|
||
<section class="categories categories_page">
|
||
<div class="categories-container container">
|
||
<h2>Продукция</h2>
|
||
<div class="categories-main">
|
||
<div class="categories-grid">
|
||
<?php
|
||
$categories = get_terms([
|
||
'taxonomy' => 'product_cat',
|
||
'parent' => 0,
|
||
'hide_empty' => false,
|
||
]);
|
||
if (!empty($categories) && !is_wp_error($categories)) {
|
||
foreach ($categories as $category) {
|
||
if ($category->name === 'Misc') {
|
||
continue;
|
||
}
|
||
$thumb_id = get_term_meta($category->term_id, 'thumbnail_id', true);
|
||
$thumb_url = $thumb_id ? wp_get_attachment_image_url($thumb_id, 'full') : '/wp-content/uploads/woocommerce-placeholder.png';
|
||
$term_link = get_term_link($category);
|
||
?>
|
||
<div class="categories-item">
|
||
<a href="<?php echo esc_url($term_link); ?>" class="categories-item__img">
|
||
<img src="<?php echo esc_url($thumb_url); ?>" alt="<?php echo esc_attr($category->name); ?>">
|
||
</a>
|
||
<div class="categories-item__main">
|
||
<a href="<?php echo esc_url($term_link); ?>" class="categories-item__title">
|
||
<?php echo esc_html($category->name); ?>
|
||
<svg width="24" height="25" viewBox="0 0 24 25" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#clip0_305_8960)"><path d="M23.12 10.41L19.25 6.50002C19.157 6.40629 19.0464 6.3319 18.9246 6.28113C18.8027 6.23036 18.672 6.20422 18.54 6.20422C18.408 6.20422 18.2773 6.23036 18.1554 6.28113C18.0336 6.3319 17.923 6.40629 17.83 6.50002C17.6437 6.68738 17.5392 6.94084 17.5392 7.20502C17.5392 7.46921 17.6437 7.72266 17.83 7.91002L21.39 11.5H1C0.734784 11.5 0.48043 11.6054 0.292893 11.7929C0.105357 11.9805 0 12.2348 0 12.5H0C0 12.7652 0.105357 13.0196 0.292893 13.2071C0.48043 13.3947 0.734784 13.5 1 13.5H21.45L17.83 17.11C17.7363 17.203 17.6619 17.3136 17.6111 17.4354C17.5603 17.5573 17.5342 17.688 17.5342 17.82C17.5342 17.952 17.5603 18.0827 17.6111 18.2046C17.6619 18.3265 17.7363 18.4371 17.83 18.53C17.923 18.6238 18.0336 18.6981 18.1554 18.7489C18.2773 18.7997 18.408 18.8258 18.54 18.8258C18.672 18.8258 18.8027 18.7997 18.9246 18.7489C19.0464 18.6981 19.157 18.6238 19.25 18.53L23.12 14.65C23.6818 14.0875 23.9974 13.325 23.9974 12.53C23.9974 11.735 23.6818 10.9725 23.12 10.41Z" fill="#02ADEF"/></g><defs><clipPath id="clip0_305_8960"><rect width="24" height="24" fill="white" transform="translate(0 0.5)"/></clipPath></defs></svg>
|
||
</a>
|
||
</div>
|
||
</div>
|
||
<?php
|
||
}
|
||
}
|
||
?>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<?php get_template_part( 'blocks/block', 'consult' ); ?>
|
||
</main>
|
||
<?php get_footer(); ?>
|
||
<?php endif; ?>
|