| Server IP : 104.171.130.249 / Your IP : 216.73.216.146 Web Server : nginx/1.25.5 System : Linux 0dac65491b7e 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : root ( 0) PHP Version : 8.4.23 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /var/www/html/wp-content/themes/matreshka/inc/ |
Upload File : |
<?php
/**
* Product display helper functions.
*/
function matreshka_get_sale_percentage( $product ) {
if ( ! $product instanceof WC_Product ) {
return false;
}
$regular_price = (float) $product->get_regular_price();
$sale_price = (float) $product->get_sale_price();
if ( ! $sale_price || ! $regular_price || $sale_price >= $regular_price ) {
return false;
}
$percentage = round( ( ( $regular_price - $sale_price ) / $regular_price ) * 100 );
return $percentage > 0 ? $percentage : false;
}
function matreshka_get_product_price_html( $product, $wrapper_class = 'product-card-price' ) {
if ( ! $product instanceof WC_Product ) {
return '';
}
$regular_price = $product->get_regular_price();
$sale_price = $product->get_sale_price();
$output = '<div class="' . esc_attr( $wrapper_class ) . '">';
if ( $sale_price ) {
$output .= '<h3 class="montserrat-bold text-red-primary">';
$output .= matreshka_format_price( $sale_price, true, 'text-red-primary' );
$output .= '</h3>';
$output .= '<span class="montserrat-semibold text-dark-opacity price-old">' . matreshka_format_price( $regular_price ) . '</span>';
} else {
$output .= '<h3 class="montserrat-bold">';
$output .= matreshka_format_price( $regular_price );
$output .= '</h3>';
}
$output .= '</div>';
return $output;
}
function matreshka_get_product_card_image_html( $product, $alt = '' ) {
if ( ! $product instanceof WC_Product ) {
return matreshka_get_product_card_placeholder_html();
}
$alt = $alt ?: $product->get_name();
$image_id = (int) $product->get_image_id();
$image_url = matreshka_get_product_card_image_url( $product );
if ( $image_id && $image_url ) {
$image_html = wp_get_attachment_image(
$image_id,
'woocommerce_thumbnail',
false,
array(
'alt' => $alt,
'class' => 'product-card-image',
'loading' => 'lazy',
'data-product-card-image' => 'true',
)
);
if ( $image_html ) {
return $image_html . matreshka_get_product_card_placeholder_html( 'product-card-placeholder product-card-placeholder-fallback' );
}
}
return matreshka_get_product_card_placeholder_html();
}
function matreshka_get_product_card_image_url( $product, $size = 'woocommerce_thumbnail' ) {
if ( ! $product instanceof WC_Product ) {
return '';
}
$image_id = (int) $product->get_image_id();
if ( ! $image_id ) {
return '';
}
return wp_get_attachment_image_url( $image_id, $size ) ?: '';
}
function matreshka_get_product_card_placeholder_html( $class = 'product-card-placeholder' ) {
$logo_url = get_template_directory_uri() . '/assets/icons/matreshka.svg';
return sprintf(
'<div class="%s" role="img" aria-label="%s"><img class="product-card-placeholder-logo" src="%s" alt=""></div>',
esc_attr( $class ),
esc_attr__( 'Изображение товара отсутствует', 'matreshka' ),
esc_url( $logo_url )
);
}
function matreshka_get_history_product_image_html( $product, $alt = '', $size = 'woocommerce_thumbnail' ) {
$alt = $alt ?: ( $product instanceof WC_Product ? $product->get_name() : __( 'Товар', 'matreshka' ) );
$media_html = '';
$media_class = 'history-product-media';
if ( $product instanceof WC_Product ) {
$image_id = (int) $product->get_image_id();
if ( $image_id && wp_get_attachment_image_url( $image_id, $size ) ) {
$media_html = wp_get_attachment_image(
$image_id,
$size,
false,
array(
'alt' => $alt,
'class' => 'history-product-image',
'loading' => 'lazy',
'data-history-product-image' => 'true',
)
);
}
}
if ( $media_html ) {
$media_html .= matreshka_get_product_card_placeholder_html( 'product-card-placeholder history-product-placeholder history-product-placeholder-fallback' );
} else {
$media_html = matreshka_get_product_card_placeholder_html( 'product-card-placeholder history-product-placeholder' );
}
return sprintf(
'<div class="%s">%s</div>',
esc_attr( $media_class ),
$media_html
);
}
function matreshka_get_sale_badge( $product, $position = 'card' ) {
$percentage = matreshka_get_sale_percentage( $product );
if ( ! $percentage ) {
return '';
}
$class = $position === 'single' ? 'sale-badge sale-badge-single' : 'sale-badge sale-badge-card';
return '<span class="' . esc_attr( $class ) . '">-' . esc_html( $percentage ) . '%</span>';
}