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/page-shop.php

200 lines
4.7 KiB

<?php
/**
* Template Name: Shop page
*
*
* @package Woodmart
*/
defined( 'ABSPATH' ) || exit;
if( isset($_GET['ajax_load']) ) {
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' );
}
}
die();
}
$loc = pll_current_language();
if ($loc == 'en'){
get_header('gp_eng');
}
else{
get_header('gp');
}
/**
* Hook: woocommerce_before_main_content.
*
* @hooked woocommerce_output_content_wrapper - 10 (outputs opening divs for the content)
* @hooked woocommerce_breadcrumb - 20
* @hooked WC_Structured_Data::generate_website_data() - 30
*/
/**
* Hook: woocommerce_shop_loop_header.
*
* @since 8.6.0
*
* @hooked woocommerce_product_taxonomy_archive_header - 10
*/
// do_action( 'woocommerce_shop_loop_header' );
function count_active_products_in_current_category() {
// Get the current term (category)
if (is_product_category()) {
$current_category = get_queried_object();
// Set up the query arguments
$args = array(
'post_type' => 'product',
'post_status' => 'publish', // Only active products
'posts_per_page' => -1, // Get all products
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'term_id',
'terms' => $current_category->term_id,
),
),
);
// Query the products
$products = new WP_Query($args);
// Return the count of products
return $products->found_posts;
}
return 0; // Return 0 if not in a product category
}
if (get_queried_object()){
$p_count = count_active_products_in_current_category();
}
else{
$p_count = 1;
}
?>
<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 ( $p_count >= 0 ) {
/**
* Hook: woocommerce_before_shop_loop.
*
* @hooked woocommerce_output_all_notices - 10
* @hooked woocommerce_result_count - 20
* @hooked woocommerce_catalog_ordering - 30
*/
// do_action( 'woocommerce_before_shop_loop' );
woocommerce_product_loop_start();
if ( wc_get_loop_prop( 'total' ) ) {
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();
/**
* Hook: woocommerce_after_shop_loop.
*
* @hooked woocommerce_pagination - 10
*/
// do_action( 'woocommerce_after_shop_loop' );
} 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
global $wp_query;
// текущая страница
$paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;
$max_pages = $wp_query->max_num_pages;
?>
<div class="product__footer product__footer--error">
<? if( $paged < $max_pages && $p_count > 0) {
?>
<button class="button button--white btn-load-ajax" data-page="<?php echo $paged ?>" 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();