You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
cosmopet.ae/wp-content/themes/woodmart/woocommerce/archive-product.php

194 lines
7.4 KiB

<?php
/**
* The Template for displaying product archives, including the main shop page which is a post type archive
*
* This template can be overridden by copying it to yourtheme/woocommerce/archive-product.php.
*
* @see https://woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
* @version 8.6.0
*/
defined('ABSPATH') || exit;
// AJAX-загрузка товаров
if (isset($_GET['ajax_load'])) {
$paged = isset($_GET['page']) ? intval($_GET['page']) : 1; // Получаем номер страницы из AJAX
$args = array(
'post_type' => 'product',
'post_status' => array('publish'),
'posts_per_page' => 12, // 12 товаров на страницу
'paged' => $paged, // Учитываем пагинацию
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => array(719, 567, 713),
'operator' => 'IN',
),
),
);
$products = new WP_Query($args);
while ($products->have_posts()) {
$products->the_post();
global $product;
$product_type = $product->get_type();
if (!in_array($product_type, array('subscription', 'subscription_variation', 'variable-subscription'))) {
wc_get_template_part('content', 'product');
}
}
wp_reset_postdata();
die();
}
$loc = pll_current_language();
if ($loc == 'en') {
get_header('gp_eng');
} else {
get_header('gp');
}
// Определение, является ли страница магазином или имеет ID 18164
$is_shop_page = is_shop() || get_queried_object_id() == 18164;
// Настройка запроса для страницы магазина
if ($is_shop_page) {
$args = array(
'post_type' => 'product',
'post_status' => array('publish'),
'posts_per_page' => -1, // Ограничиваем до 12 товаров на первой загрузке
'paged' => get_query_var('paged') ? get_query_var('paged') : 1, // Учитываем пагинацию
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => array(719, 567, 713),
'operator' => 'IN',
),
),
);
$products = new WP_Query($args);
$p_count = $products->found_posts; // Всего товаров в запросе
} else if (is_product_category()) {
// Для страниц категорий
$current_category = get_queried_object();
$args = array(
'post_type' => 'product',
'post_status' => 'publish',
'posts_per_page' => -1, // Можно оставить -1, если пагинация не нужна для категорий
'paged' => get_query_var('paged') ? get_query_var('paged') : 1,
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $current_category->term_id,
),
),
);
$products = new WP_Query($args);
$p_count = $products->found_posts;
} else {
// Для других страниц
$p_count = wc_get_loop_prop('total', 0);
}
?>
<main class="wrapper">
<div class="breadcrumbs">
<a href="<?php echo home_url() ?>" class="breadcrumbs__item">
<?php echo esc_html__('main', 'woodmart') ?>
</a>
<a href="<?php echo get_permalink(wc_get_page_id('shop')) ?>" class="breadcrumbs__item">
<?php echo esc_html__('products', 'woodmart') ?>
</a>
</div>
<div class="product">
<div class="product__header">
<p class="product__title"><?php woocommerce_page_title(); ?></p>
<button class="button button--gradient button--high button--icon button--filter">
<?php echo esc_html__('filters', 'woodmart') ?>
</button>
</div>
<div class="product__tag">
<!-- Здесь могут быть теги, если нужны -->
</div>
<div class="product__main">
<?php
if ($is_shop_page && $products->have_posts()) {
woocommerce_product_loop_start();
while ($products->have_posts()) {
$products->the_post();
global $product;
$product_type = $product->get_type();
if (!in_array($product_type, array('subscription', 'subscription_variation', 'variable-subscription'))) {
wc_get_template_part('content', 'product');
}
}
woocommerce_product_loop_end();
wp_reset_postdata();
} else if (is_product_category() && $products->have_posts()) {
woocommerce_product_loop_start();
while ($products->have_posts()) {
$products->the_post();
global $product;
$product_type = $product->get_type();
if (!in_array($product_type, array('subscription', 'subscription_variation', 'variable-subscription'))) {
wc_get_template_part('content', 'product');
}
}
woocommerce_product_loop_end();
wp_reset_postdata();
} else if (wc_get_loop_prop('total') > 0) {
woocommerce_product_loop_start();
while (have_posts()) {
the_post();
global $product;
$product_type = $product->get_type();
if (!in_array($product_type, array('subscription', 'subscription_variation', 'variable-subscription'))) {
wc_get_template_part('content', 'product');
}
}
woocommerce_product_loop_end();
} else {
?>
<div class="not-found">
<img src="<?= get_template_directory_uri() ?>/images/sv.svg" alt="">
<div class="not-found-title">coming soon</div>
<div class="not-found-text">This item is not on our website yet, but it will be here very soon</div>
</div>
<?php
}
?>
</div>
<?php
$paged = $products->get('paged') ? $products->get('paged') : 1;
$max_pages = $products->max_num_pages; // Максимальное количество страниц из WP_Query
?>
<div class="product__footer product__footer--error">
<?php if ($is_shop_page && $p_count > 12 && $paged < $max_pages) { ?>
<button class="button button--white btn-load-ajax" data-page="<?php echo $paged + 1 ?>" data-maxpage="<?php echo $max_pages ?>">
<?php echo esc_html__('load more', 'woodmart') ?>
</button>
<?php } ?>
<a href="<?php echo get_permalink(wc_get_page_id('shop')) ?>" class="product__error-button" style="display:none;">
<?php echo esc_html__('reset search query', 'woodmart') ?>
</a>
</div>
</div>
</main>
<?php
do_action('woocommerce_sidebar');
if ($loc == 'en') {
get_footer('gp_eng');
} else {
get_footer('gp');
}
wp_footer();