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
126 lines
5.1 KiB
PHP
126 lines
5.1 KiB
PHP
<!--
|
||
Template Name: Шаблон Корзина
|
||
-->
|
||
<?php get_header(); ?>
|
||
<main>
|
||
<nav class="breadcumbs container">
|
||
<ul>
|
||
<li><a href="/">Главная</a></li>
|
||
<li><p class="breadcumbs-separator">/</p></li>
|
||
<li><p><?php echo the_title(); ?></p></li>
|
||
</ul>
|
||
</nav>
|
||
<?php echo do_shortcode('[woocommerce_cart]'); ?>
|
||
<?php
|
||
// Рекомендуемые товары для корзины
|
||
$cart_product_ids = array();
|
||
$cart_categories = array();
|
||
|
||
if ( WC()->cart && ! WC()->cart->is_empty() ) {
|
||
foreach ( WC()->cart->get_cart() as $item ) {
|
||
$cart_product_ids[] = $item['product_id'];
|
||
$terms = wp_get_post_terms( $item['product_id'], 'product_cat', array( 'fields' => 'ids' ) );
|
||
$cart_categories = array_merge( $cart_categories, $terms );
|
||
}
|
||
$cart_categories = array_unique( $cart_categories );
|
||
}
|
||
|
||
$rec_args = array(
|
||
'post_type' => 'product',
|
||
'posts_per_page' => 8,
|
||
'post__not_in' => $cart_product_ids,
|
||
'ignore_sticky_posts' => 1,
|
||
'post_status' => array( 'publish', 'draft' ),
|
||
'orderby' => 'rand',
|
||
'meta_query' => array(
|
||
array(
|
||
'key' => '_is_recommended_product',
|
||
'value' => 'yes',
|
||
),
|
||
),
|
||
);
|
||
if ( ! empty( $cart_categories ) ) {
|
||
$rec_args['tax_query'] = array(
|
||
array(
|
||
'taxonomy' => 'product_cat',
|
||
'field' => 'term_id',
|
||
'terms' => $cart_categories,
|
||
'operator' => 'IN',
|
||
),
|
||
);
|
||
}
|
||
$rec_query = new WP_Query( $rec_args );
|
||
$rec_ids = wp_list_pluck( $rec_query->posts, 'ID' );
|
||
|
||
$remaining = 8 - count( $rec_ids );
|
||
$random_products = array();
|
||
if ( $remaining > 0 ) {
|
||
$exclude = array_merge( $cart_product_ids, $rec_ids );
|
||
$rand_args = array(
|
||
'post_type' => 'product',
|
||
'posts_per_page' => $remaining,
|
||
'post__not_in' => $exclude,
|
||
'ignore_sticky_posts' => 1,
|
||
'post_status' => array( 'publish', 'draft' ),
|
||
'orderby' => 'rand',
|
||
);
|
||
if ( ! empty( $cart_categories ) ) {
|
||
$rand_args['tax_query'] = array(
|
||
array(
|
||
'taxonomy' => 'product_cat',
|
||
'field' => 'term_id',
|
||
'terms' => $cart_categories,
|
||
'operator' => 'IN',
|
||
),
|
||
);
|
||
}
|
||
$rand_query = new WP_Query( $rand_args );
|
||
$random_products = $rand_query->posts;
|
||
}
|
||
|
||
$all_products = array_merge( $rec_query->posts, $random_products );
|
||
|
||
if ( ! empty( $all_products ) ) :
|
||
global $post;
|
||
?>
|
||
<section class="cart_more">
|
||
<div class="cart_more-container container">
|
||
<div class="cart_more-name">
|
||
<h2>Рекомендуемые товары</h2>
|
||
<a href="/catalog" class="cart_more-link">
|
||
Все товары
|
||
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M15.0007 9.99989C14.9966 9.56147 14.8199 9.14231 14.509 8.83323L10.934 5.2499C10.7778 5.09469 10.5666 5.00757 10.3465 5.00757C10.1263 5.00757 9.91512 5.09469 9.75898 5.2499C9.68088 5.32736 9.61888 5.41953 9.57657 5.52108C9.53427 5.62263 9.51249 5.73155 9.51249 5.84156C9.51249 5.95157 9.53427 6.06049 9.57657 6.16204C9.61888 6.26359 9.68088 6.35576 9.75898 6.43323L12.5007 9.16656H4.16732C3.9463 9.16656 3.73434 9.25435 3.57806 9.41064C3.42178 9.56692 3.33398 9.77888 3.33398 9.99989C3.33398 10.2209 3.42178 10.4329 3.57806 10.5891C3.73434 10.7454 3.9463 10.8332 4.16732 10.8332H12.5007L9.75898 13.5749C9.60206 13.7307 9.51347 13.9425 9.51269 14.1636C9.51191 14.3847 9.599 14.5971 9.75482 14.7541C9.91063 14.911 10.1224 14.9996 10.3435 15.0003C10.5647 15.0011 10.7771 14.914 10.934 14.7582L14.509 11.1749C14.822 10.8638 14.9988 10.4412 15.0007 9.99989Z" fill="#02ADEF"/></svg>
|
||
</a>
|
||
</div>
|
||
<div class="products-slider">
|
||
<div class="products-swiper swiper">
|
||
<div class="swiper-wrapper">
|
||
<?php foreach ( $all_products as $related_product ) :
|
||
$post = $related_product;
|
||
setup_postdata( $post ); ?>
|
||
<div class="swiper-slide">
|
||
<?php wc_get_template_part( 'content', 'product' ); ?>
|
||
</div>
|
||
<?php endforeach;
|
||
wp_reset_postdata(); ?>
|
||
</div>
|
||
</div>
|
||
<button class="products-prev"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M10.0596 13.28L5.7129 8.9333C5.19957 8.41997 5.19957 7.57997 5.7129 7.06664L10.0596 2.71997" stroke="white" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
|
||
<button class="products-next"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M5.94043 13.28L10.2871 8.9333C10.8004 8.41997 10.8004 7.57997 10.2871 7.06664L5.94043 2.71997" stroke="white" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/></svg></button>
|
||
</div>
|
||
<div class="cart_more-mob">
|
||
<div class="products-mob">
|
||
<?php foreach ( $all_products as $related_product ) :
|
||
$post = $related_product;
|
||
setup_postdata( $post );
|
||
wc_get_template_part( 'content', 'product' );
|
||
endforeach;
|
||
wp_reset_postdata(); ?>
|
||
</div>
|
||
<a href="/catalog" class="cart_more-mob__link">Все товары</a>
|
||
</div>
|
||
</div>
|
||
</section>
|
||
<?php endif; ?>
|
||
</main>
|
||
<?php get_footer(); ?>
|