Jamil-Abdullayev b8246597d4 Initial commit: orgsteklo WordPress theme
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
2026-03-05 00:48:06 +04:00

152 lines
6.2 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
defined( 'ABSPATH' ) || exit;
global $product;
if ( empty( $product ) || ! $product->is_visible() ) {
return;
}
$current_product_id = get_the_ID();
?>
<div class="product_item">
<div class="product_item-img">
<?php
$product_id = $product->get_id();
$product_link = get_permalink( $product_id );
echo '<a href="' . esc_url($product_link) . '" class="product_item-img__link">';
$product_image_id = $product->get_image_id();
if ( $product_image_id ) {
$image_url = wp_get_attachment_image_url( $product_image_id, 'full' );
echo '<img src="' . esc_url( $image_url ) . '" alt="' . esc_attr( $product->get_name() ) . '">';
}
else {
$placeholder_url = wc_placeholder_img_src( 'woocommerce_single' );
echo '<img src="' . esc_url( $placeholder_url ) . '" alt="' . esc_attr( $product->get_name() ) . '">';
}
echo '</a>';
?>
<?php
// Получаем отсортированные теги (сначала статус, потом скидки)
$sorted_tags = get_sorted_product_tags( get_the_ID() );
if ( ! empty( $sorted_tags ) ) {
echo '<div class="product_item-labels">';
// Выводим все метки (статусные и скидки)
// Теперь метки со скидками автоматически применяют скидку к цене через хуки
foreach ( $sorted_tags as $tag ) {
$is_discount = is_discount_tag( $tag->name );
$class = $is_discount ? 'product_item-discount' : 'product_item-popular';
echo '<p class="' . esc_attr( $class ) . '">' . esc_html( $tag->name ) . '</p>';
}
echo '</div>';
}
?>
</div>
<div class="product_item-main">
<a href="<?php echo esc_url( $product_link ); ?>" class="product_item-title"><?php echo esc_html( $product->get_name() ); ?></a>
<?php
$char_1 = get_post_meta( $product->get_id(), '_preview_char_1', true );
$char_2 = get_post_meta( $product->get_id(), '_preview_char_2', true );
if ( $char_1 || $char_2 ) {
echo '<ul class="product_item-chars">';
if ( $char_1 ) {
echo '<li>' . esc_html( $char_1 ) . '</li>';
}
if ( $char_2 ) {
echo '<li>' . esc_html( $char_2 ) . '</li>';
}
echo '</ul>';
}
?>
<div class="product_item-meta">
<?php
// Универсальный вывод цен для всех типов товаров
if ( $product ) {
$display_product = $product;
// Для вариативных товаров берём первую вариацию
if ( $product->is_type( 'variable' ) ) {
$available_variations = $product->get_available_variations();
$variation_id = $available_variations[0]['variation_id'] ?? null;
if ( $variation_id ) {
$display_product = wc_get_product( $variation_id );
}
}
// Получаем цены (с учётом автоматических скидок по меткам)
$price = wc_get_price_to_display( $display_product );
$regular_price = wc_get_price_to_display( $display_product, [ 'price' => $display_product->get_regular_price() ] );
// Проверяем, является ли товар оргстеклом
$is_orgsteklo_product = ! empty( get_post_meta( $product->get_id(), '_orgsteklo_price_table', true ) );
if ( $is_orgsteklo_product && function_exists( 'orgsteklo_get_product_table_data' ) && function_exists( 'orgsteklo_calculate_standard_size' ) ) {
// ОРГСТЕКЛО — цены из таблицы калькулятора
$table_data = orgsteklo_get_product_table_data( $product->get_id() );
if ( $table_data && ! empty( $table_data['rows'] ) ) {
$first_row = $table_data['rows'][0];
$calc_result = orgsteklo_calculate_standard_size( $product->get_id(), $first_row['thickness'], 1 );
if ( ! is_wp_error( $calc_result ) ) {
$sheet_price = $calc_result['price_standard_sheet'];
$kg_price = $calc_result['price_per_kg_standard'];
// Проверяем скидку из тегов
$discount_percent = 0;
if ( function_exists('get_sorted_product_tags') && function_exists('is_discount_tag') && function_exists('get_discount_from_tag_name') ) {
$tags = get_sorted_product_tags( $product->get_id() );
foreach ( $tags as $tag ) {
if ( is_discount_tag( $tag->name ) ) {
$discount_percent = get_discount_from_tag_name( $tag->name );
break;
}
}
}
$regular_sheet_price = $sheet_price;
$regular_kg_price = $kg_price;
if ( $discount_percent > 0 ) {
$sheet_price = round( $regular_sheet_price * ( 1 - $discount_percent / 100 ) );
$kg_price = round( $regular_kg_price * ( 1 - $discount_percent / 100 ) );
}
// Цена за лист
echo '<div class="product_item-prices">';
echo '<p class="product_item-price">' . wc_price( $sheet_price ) . '/лист</p>';
if ( $discount_percent > 0 ) {
echo '<p class="product_item-oldprice">' . wc_price( $regular_sheet_price ) . '</p>';
}
echo '</div>';
// Цена за кг
echo '<div class="product_item-price_weight">';
echo '<p class="product_item-price_weight-new">' . wc_price( $kg_price ) . '/кг</p>';
if ( $discount_percent > 0 ) {
echo '<p class="product_item-price_weight-old">' . wc_price( $regular_kg_price ) . '</p>';
}
echo '</div>';
}
}
} else {
// Остальные товары — цена за штуку
echo '<div class="product_item-prices">';
echo '<p class="product_item-price">' . wc_price( $price ) . '/штука</p>';
if ( $regular_price > $price ) {
echo '<p class="product_item-oldprice">' . wc_price( $regular_price ) . '</p>';
}
echo '</div>';
}
}
?>
<!-- <div class="product_item-prices">
<p class="product_item-price">15 964 ₽/лист</p>
<p class="product_item-oldprice">16 989 ₽</p>
</div>
<div class="product_item-price_weight">
<p class="product_item-price_weight-new">4 589 ₽/кг</p>
<p class="product_item-price_weight-old">5 589 ₽</p>
</div> -->
</div>
<a href="<?php echo esc_url( $product_link ); ?>" class="product_item-link">Подробнее</a>
</div>
</div>