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 copy/themes/woodmart/woocommerce/content-product.php

600 lines
29 KiB

<?php
/**
* The template for displaying product content within loops
*
* This template can be overridden by copying it to yourtheme/woocommerce/content-product.php.
*
* HOWEVER, on occasion WooCommerce will need to update template files and you
* (the theme developer) will need to copy the new files to your theme to
* maintain compatibility. We try to do this as little as possible, but it does
* happen. When this occurs the version of the template file will be bumped and
* the readme will list any important changes.
*
* @see https://woocommerce.com/document/template-structure/
* @package WooCommerce\Templates
* @version 9.4.0
*/
defined( 'ABSPATH' ) || exit;
global $product;
// Check if the product is a valid WooCommerce product and ensure its visibility before proceeding.
if ( ! is_a( $product, WC_Product::class ) || ! $product->is_visible() ) {
return;
}
?>
<?php
$terms = wc_get_product_terms( get_the_ID(), 'pa_soon' );
$new = get_field('new');
$new_text = 'Новинка';
$loc = pll_current_language();
if ($loc == 'en'){
$new_text = 'New';
}
$is_available = true;
foreach ($terms as $term) {
if($term -> name){
$is_available = false;
?>
<? };
}
if ($product->get_type() != 'variable'){
$stock = $product->get_stock_quantity();
if($stock == 0){
$is_available = false;
}
}
$tags = wc_get_product_terms( get_the_ID(), 'pa_catalog_tags' );
?>
<?php
if ($product->get_type() == 'variation'):
$_product = wc_get_product( $product->get_parent_id() );
$available_variations = $_product->get_available_variations();
$tags = wc_get_product_terms( $product->get_parent_id(), 'pa_catalog_tags' );
$weight_list = [];
$terms = wc_get_product_terms( $product->get_parent_id(), 'pa_soon' );
foreach ($terms as $term) {
if($term -> name){
$is_available = false;
?>
<? };
}
$is_sale = false;
if ($product->get_sale_price()){
$is_sale = true;
}
foreach( $available_variations as $variation ) {
$variation_obj = new WC_Product_Variation($variation['variation_id']);
if( $variation_obj->has_weight() ) {
$weight = $variation_obj->get_weight();
$weight_list[] = array(
'weight'=> $weight,
'price'=> $variation_obj->get_price(),
'id'=> $variation_obj->get_id(),
'stock' => $variation_obj->get_stock_quantity(),
);
}
}
// ?>
<?php
if (is_product()):
?>
<div class="swiper-slide">
<?php
endif;
?>
<div class="product__item<?php if(!$is_available){ echo ' hiding';} ?>">
<div class="product-item__label">
<?php
if ( $new ):
?>
<span class="product-item-label__tag product-item-label__tag--new">
<?= $new_text; ?>
</span>
<?php
endif;
?>
</div>
<a href="<?php the_permalink() ?>" class="product-item__product-card">
<?php $post_thumbnail_id = $product->get_image_id(); ?>
<img src="<?php echo wp_get_attachment_url( $post_thumbnail_id ); ?>" alt="" class="product-item__images">
</a>
<div class="product-item__content-card">
<div class="compound">
<?php
foreach($tags as $tag):
?>
<a href="<?php echo get_term_link( $tag, 'pa_catalog_tags' ); ?>" class="compound__item"><?php echo $tag -> name ?></a>
<?php endforeach; ?>
<?php if ($is_sale): ?>
<div class="product-item-label__tag product-item-label__tag--sale">
<?php echo esc_html__( 'Sale %', 'woodmart' ) ?>
</div>
<?php
endif;
?>
</div>
<a href="<?php the_permalink() ?>" class="product-item__title"><?php the_title() ?></a>
<div class="product-item__price">
<p><?php echo $product->get_price() ?></p>
<?php
if($product->get_sale_price()):
?>
<div class="product-item__price-disc">
<p class="product-item__price-sale__text">
<?= $product->get_regular_price() ?>
</p>
<p class="product-item__price-sale__perc">
- <?= round(($product->get_regular_price() - $product->get_price()) / $product->get_regular_price() * 100) ?> %
</p>
</div>
<?php endif; ?>
</div>
<?php if ($is_available): ?>
<div class="product-item__bye">
<button class="button button--white button--100-perc open-overlay">
<?php echo esc_html__( 'Buy', 'woodmart' ); ?>
</button>
</div>
<?php
else:
?>
<div class="product-item__bye">
<button data-pname="<?php the_title() ?>" class="to-know button--100-perc open-to-know">
<p> <?php echo esc_html__( 'Subscribe to get', 'woodmart' ) ?></p>
</button>
</div>
<?php
endif;
?>
</div>
<div class="product-item__overlay">
<div class="product-item-overlay__header">
<a href="#" class="product-item__title"><?php the_title() ?> </a>
<ul class="product-item-overlay__tags">
<?php
foreach($tags as $tag):
?>
<li><?php echo $tag -> name ?></li>
<?php endforeach; ?>
</ul>
</div>
<form class="product-item__form" method="post" action="<?php echo admin_url( 'admin-ajax.php' ) ?>">
<div class="product-item-overlay__input-block">
<div class="product-item-overlay__field">
<p class="product-item-overlay-field__title"> <?php echo esc_html__( 'Volume', 'woodmart' ) ?></p>
<div class="select">
<input type="text" class="select__state" value="<?php echo $product->get_weight() ?> <?php echo esc_html__( 'kg', 'woodmart' ) ?>" readonly>
<div class="state__block">
<ul class="state__content">
<?php
foreach ($weight_list as $w_item):
$active_class = '';
if ($w_item['weight'] == $product->get_weight()){
$active_class = ' active';
}
if ($w_item['stock'] > 0):
?>
<li>
<button data-stock="<?php echo $w_item['stock'] ?>" class="state__button<?php echo $active_class ?>" data-id="<?php echo $w_item['id'] ?>" data-bc="<?php echo $w_item['price'] ?>">
<?php echo $w_item['weight'] ?> <?php echo esc_html__( 'kg', 'woodmart' ) ?>
</button>
</li>
<?php
endif;
endforeach; ?>
</ul>
</div>
</div>
</div>
<div class="product-item-overlay__field">
<p class="product-item-overlay-field__title"><?php echo esc_html__( 'Count', 'woodmart' ) ?></p>
<div class="counter">
<button class="counter__button minus" type="button">
<img src="<?= get_template_directory_uri();?>/gp-include/assets/core/img/svg/main/minus.svg" alt="">
</button>
<input type="text" name="quantity" class="counter__input" data-maxcount="<?php echo $product->get_stock_quantity() ?>" value="1">
<button class="counter__button plus" type="button">
<img src="<?= get_template_directory_uri();?>/gp-include/assets/core/img/svg/main/plus.svg" alt="">
</button>
</div>
</div>
</div>
<p data-basecost="<?php echo $product->get_price() ?>" class="product-item-overlay__price">
<?php echo $product->get_price() ?>
</p>
<div class="product-item-overlay__block-button">
<div class="product-item-overlay__button">
<input type="hidden" name="variation_id" value="<?php echo $product->get_ID() ?>">
<input type="hidden" name="product_id" value="<?php echo $product->get_parent_id() ?>">
<button data-quantity="1" class="store-add-to-cart button button--gradient button--base button--100-perc"><?php echo esc_html__( 'Add to cart', 'woodmart' ) ?></button>
</div>
<div class="product-item-overlay__button">
<a href="<?php the_permalink() ?>" class="to-know button--100-perc">
<p><?php echo esc_html__( 'Learn more', 'woodmart' ) ?></p>
</a>
</div>
</div>
</form>
</div>
</div>
<?php
if (is_product()):
?>
</div>
<?php
endif;
?>
<?php
elseif ($product->get_type() == 'variable'):
$available_variations = $product->get_available_variations();
$weight_list = [];
foreach( $available_variations as $variation ) {
$variation_obj = new WC_Product_Variation($variation['variation_id']);
if( $variation_obj->has_weight() ) {
$weight = $variation_obj->get_weight();
$weight_list[] = array(
'weight'=> $weight,
'price'=> $variation_obj->get_price(),
'id'=> $variation_obj->get_id(),
'stock' => $variation_obj->get_stock_quantity(),
);
}
}
foreach( $available_variations as $variation_item ) :
$is_sale = false;
$variation= new WC_Product_Variation($variation_item['variation_id']);
$stock = $variation->get_stock_quantity();
if($stock == 0){
$is_available = false;
}
if ($variation->get_sale_price()){
$is_sale = true;
}
?>
<?php
if (is_product()):
?>
<div class="swiper-slide">
<?php
endif;
?>
<?php
$variat = wc_get_product( $variation_item['variation_id'] );
//$var_slug = implode( ' / ', $variat->get_variation_attributes() );
$variations = $variat->get_variation_attributes();
$var_slug = $variations['attribute_pa_weight'];
$var_label = get_term_by('slug', $var_slug, 'pa_weight');
$var_label = substr($var_label->name, 0, strrpos($var_label->name, ' '));
$var_intLabel = (float)$var_label;
$ves = $args['ves'];
$ves_bolshaya = array('bolshaya-upakovka', 'large');
if( empty($ves) || (isset($ves) && in_array($ves,$ves_bolshaya) ? $var_intLabel >= 3 : $var_intLabel <= 3)): ?>
<div class="product__item <?php if(!$is_available){ echo ' hiding';} ?>">
<div class="product-item__label">
<?php
if ( $new ):
?>
<span class="product-item-label__tag product-item-label__tag--new">
<?= $new_text; ?>
</span>
<?php
endif;
?>
</div>
<a href="<?php echo get_permalink( $variation->ID ) ?>?attribute_pa_weight=<?php echo $variation->get_attributes()['pa_weight'] ?>" class="product-item__product-card">
<?php $post_thumbnail_id = $variation->get_image_id(); ?>
<img src="<?php echo wp_get_attachment_url( $post_thumbnail_id ); ?>" alt="" class="product-item__images">
</a>
<div class="product-item__content-card">
<div class="compound">
<?php
foreach($tags as $tag):
?>
<a href="<?php echo get_permalink( $variation->ID ) ?>" class="compound__item"><?php echo $tag -> name ?></a>
<?php endforeach; ?>
<?php if ($is_sale): ?>
<div class="product-item-label__tag product-item-label__tag--sale">
<?php echo esc_html__( 'Sale %', 'woodmart' ) ?>
</div>
<?php
endif;
?>
</div>
<a href="<?php echo get_permalink( $variation->ID ) ?>?attribute_pa_weight=<?php echo $variation->get_attributes()['pa_weight'] ?>" class="product-item__title"><?php echo get_the_title($variation->ID ) ?> — <?php echo $variation->get_weight() ?> <?php echo esc_html__( 'kg', 'woodmart' ) ?> </a>
<div class="product-item__price">
<p><?php echo $variation->get_price() ?></p>
<?php
if($variation->get_sale_price()):
?>
<div class="product-item__price-disc">
<p class="product-item__price-sale__text">
<?= $variation->get_regular_price() ?>
</p>
<p class="product-item__price-sale__perc">
- <?= round(($variation->get_regular_price() - $variation->get_price()) / $variation->get_regular_price() * 100) ?> %
</p>
</div>
<?php endif; ?>
</div>
<?php if ($is_available): ?>
<div class="product-item__bye">
<button class="button button--white button--100-perc open-overlay">
<?php echo esc_html__( 'Buy', 'woodmart' ); ?>
</button>
</div>
<?php
else:
?>
<div class="product-item__bye">
<button data-pname="<?php echo get_the_title($variation->ID ) ?> — <?php echo $variation->get_weight() ?> " class="to-know button--100-perc open-to-know">
<p> <?php echo esc_html__( 'Subscribe to get', 'woodmart' ) ?></p>
</button>
</div>
<?php
endif;
?>
</div>
<div class="product-item__overlay">
<div class="product-item-overlay__header">
<a href="<?php the_permalink() ?>" class="product-item__title"><?php the_title() ?></a>
<ul class="product-item-overlay__tags">
<?php
foreach($tags as $tag):
?>
<li><?php echo $tag -> name ?></li>
<?php endforeach; ?>
</ul>
</div>
<form class="product-item__form" method="post" action="<?php echo admin_url( 'admin-ajax.php' ) ?>">
<div class="product-item-overlay__input-block">
<div class="product-item-overlay__field">
<p class="product-item-overlay-field__title"> <?php echo esc_html__( 'Volume', 'woodmart' ) ?></p>
<div class="select">
<input type="text" class="select__state" value="<?php echo $variation->get_weight() ?> <?php echo esc_html__( 'kg', 'woodmart' ) ?>" readonly>
<div class="state__block">
<ul class="state__content">
<?php
foreach ($weight_list as $w_item):
$active_class = '';
if ($w_item['weight'] == $variation->get_weight()){
$active_class = ' active';
}
?>
<?php
if ($w['stock'] > 0):
?>
<li>
<button data-stock="<?php echo $w['stock'] ?>" class="state__button<?php echo $active_class ?>" data-id="<?php echo $w_item['id'] ?>" data-bc="<?php echo $w_item['price'] ?>">
<?php echo $w_item['weight'] ?> <?php echo esc_html__( 'kg', 'woodmart' ) ?>
</button>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
</div>
</div>
<div class="product-item-overlay__field">
<p class="product-item-overlay-field__title"><?php echo esc_html__( 'Count', 'woodmart' ) ?></p>
<div class="counter">
<button class="counter__button minus" type="button">
<img src="<?= get_template_directory_uri();?>/gp-include/assets/core/img/svg/main/minus.svg" alt="">
</button>
<input type="text" name="quantity" class="counter__input" data-maxcount="<?php echo $variation->get_stock_quantity() ?>" value="1">
<button class="counter__button plus" type="button">
<img src="<?= get_template_directory_uri();?>/gp-include/assets/core/img/svg/main/plus.svg" alt="">
</button>
</div>
</div>
</div>
<p data-basecost="<?php echo $variation->get_price() ?>" class="product-item-overlay__price">
<?php echo $variation->get_price() ?>
</p>
<div class="product-item-overlay__block-button">
<div class="product-item-overlay__button">
<input type="hidden" name="variation_id" value="<?php echo $variation->get_ID() ?>">
<input type="hidden" name="product_id" value="<?php echo $product->get_ID() ?>">
<button data-quantity="1" class="store-add-to-cart button button--gradient button--base button--100-perc"><?php echo esc_html__( 'Add to cart', 'woodmart' ) ?></button>
</div>
<div class="product-item-overlay__button">
<a href="<?php the_permalink() ?>" class="to-know button--100-perc">
<p><?php echo esc_html__( 'Learn more', 'woodmart' ) ?></p>
</a>
</div>
</div>
</form>
</div>
</div>
<?php endif;?>
<?php
if (is_product()):
?>
</div>
<?php
endif;
?>
<?php
endforeach;
else:
$is_sale = false;
if ($product->get_sale_price()){
$is_sale = true;
}
?>
<?php
if (is_product()):
?>
<div class="swiper-slide">
<?php
endif;
?>
<div class="product__item<?php if(!$is_available){ echo ' hiding';} ?>">
<div class="product-item__label">
<?php
if ( $new ):
?>
<span class="product-item-label__tag product-item-label__tag--new">
<?= $new_text; ?>
</span>
<?php
endif;
?>
</div>
<a href="<?php the_permalink() ?>" class="product-item__product-card">
<?php $post_thumbnail_id = $product->get_image_id(); ?>
<img src="<?php echo wp_get_attachment_url( $post_thumbnail_id ); ?>" alt="" class="product-item__images">
</a>
<div class="product-item__content-card">
<div class="compound">
<?php
foreach($tags as $tag):
?>
<a href="<?php echo get_term_link( $tag, 'pa_catalog_tags' ); ?>" class="compound__item"><?php echo $tag -> name ?></a>
<?php endforeach; ?>
<?php if ($is_sale): ?>
<div class="product-item-label__tag product-item-label__tag--sale">
<?php echo esc_html__( 'Sale %', 'woodmart' ) ?>
</div>
<?php
endif;
?>
</div>
<a href="<?php the_permalink() ?>" class="product-item__title"><?php the_title() ?></a>
<div class="product-item__price">
<p><?php echo $product->get_price() ?></p>
<?php
if($product->get_sale_price()):
?>
<div class="product-item__price-disc">
<p class="product-item__price-sale__text">
<?= $product->get_regular_price() ?>
</p>
<p class="product-item__price-sale__perc">
- <?= round(($product->get_regular_price() - $product->get_price()) / $product->get_regular_price() * 100) ?> %
</p>
</div>
<?php endif; ?>
</div>
<?php if ($is_available): ?>
<div class="product-item__bye">
<button class="button button--white button--100-perc open-overlay">
<?php echo esc_html__( 'Buy', 'woodmart' ); ?>
</button>
</div>
<?php
else:
?>
<div class="product-item__bye">
<button data-pname="<?php the_title() ?>" class="to-know button--100-perc open-to-know">
<p> <?php echo esc_html__( 'Subscribe to get', 'woodmart' ) ?></p>
</button>
</div>
<?php
endif;
?>
</div>
<div class="product-item__overlay">
<div class="product-item-overlay__header">
<a href="#" class="product-item__title"><?php the_title() ?></a>
<ul class="product-item-overlay__tags">
<?php
foreach($tags as $tag):
?>
<li><?php echo $tag -> name ?></li>
<?php endforeach; ?>
</ul>
</div>
<form class="product-item__form" method="post" action="<?php echo admin_url( 'admin-ajax.php' ) ?>">
<div class="product-item-overlay__input-block">
<div class="product-item-overlay__field">
<p class="product-item-overlay-field__title"><?php echo esc_html__( 'Count', 'woodmart' ) ?></p>
<div class="counter">
<button class="counter__button minus" type="button">
<img src="<?= get_template_directory_uri();?>/gp-include/assets/core/img/svg/main/minus.svg" alt="">
</button>
<input type="text" name="quantity" class="counter__input" data-maxcount="<?php echo $product->get_stock_quantity() ?>" value="1">
<button class="counter__button plus" type="button">
<img src="<?= get_template_directory_uri();?>/gp-include/assets/core/img/svg/main/plus.svg" alt="">
</button>
</div>
</div>
</div>
<p data-basecost="<?php echo $product->get_price() ?>" class="product-item-overlay__price">
<?php echo $product->get_price() ?>
</p>
<div class="product-item-overlay__block-button">
<div class="product-item-overlay__button">
<input type="hidden" name="product_id" value="<?php echo $product->get_ID() ?>">
<button data-quantity="1" class="store-add-to-cart button button--gradient button--base button--100-perc"><?php echo esc_html__( 'Add to cart', 'woodmart' ) ?></button>
</div>
<div class="product-item-overlay__button">
<a href="<?php the_permalink() ?>" class="to-know button--100-perc">
<p><?php echo esc_html__( 'Learn more', 'woodmart' ) ?></p>
</a>
</div>
</div>
</form>
</div>
</div>
<?php
if (is_product()):
?>
</div>
<?php
endif;
?>
<?php
endif;
?>