403Webshell
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 :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/html/wp-content/themes/matreshka/inc/price-formatter.php
<?php
/**
 * Price formatting functions for Matreshka theme
 * 
 * Custom price display: 129<span class="price-small">99</span>₽
 *
 * @package Matreshka
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly
}

/**
 * Custom price format for Matreshka theme
 * Formats every monetary amount with an always-present two-digit kopeck part.
 * For example: 100 becomes 100<span class="price-small">00</span>₽.
 *
 * @param float|string $price             Monetary amount.
 * @param bool         $show_currency     Whether to append a currency symbol.
 * @param string       $price_small_class Additional class(es) for kopecks.
 * @param string       $currency          WooCommerce currency code.
 * @return string Safe HTML price fragment.
 */
function matreshka_format_price( $price, $show_currency = true, $price_small_class = '', $currency = '' ) {
	if ( empty( $price ) && $price !== 0 && $price !== 0.0 ) {
		return $price;
	}
	
	if ( ! is_numeric( $price ) ) {
		return $price;
	}
	
	// Work in kopecks to avoid floating point artefacts such as 49.99 → 49.98.
	$kopecks_total = (int) round( abs( (float) $price ) * 100 );
	$rubles        = intdiv( $kopecks_total, 100 );
	$kopecks       = $kopecks_total % 100;
	$small_classes = trim( 'price-small ' . $price_small_class );

	$formatted  = ( (float) $price < 0 ? '-' : '' );
	$formatted .= number_format( $rubles, 0, '', ' ' );
	$formatted .= '<span class="' . esc_attr( $small_classes ) . '">' . sprintf( '%02d', $kopecks ) . '</span>';
	
	if ( $show_currency ) {
		$formatted .= esc_html( get_woocommerce_currency_symbol( $currency ) );
	}
	
	return $formatted;
}

/**
 * Override WooCommerce price HTML for cart
 */
function matreshka_cart_item_price( $price_html, $cart_item, $cart_item_key ) {
	$_product = $cart_item['data'];
	$product_price = $_product->get_price();
	
	return matreshka_format_price( $product_price );
}
add_filter( 'woocommerce_cart_item_price', 'matreshka_cart_item_price', 10, 3 );

/**
 * Format cart totals
 */
function matreshka_cart_totals_subtotal( $subtotal ) {
	// Get cart subtotal (sum of all items before discounts)
	$cart_subtotal = WC()->cart->get_subtotal();
	
	// If display prices include tax
	if ( wc_tax_enabled() && WC()->cart->display_prices_including_tax() ) {
		$cart_subtotal += WC()->cart->get_subtotal_tax();
	}
	
	return matreshka_format_price( $cart_subtotal );
}
add_filter( 'woocommerce_cart_subtotal', 'matreshka_cart_totals_subtotal', 10, 1 );

/**
 * Format cart total
 */
function matreshka_cart_total( $total ) {
	$cart_total = WC()->cart->get_total( 'edit' );
	return matreshka_format_price( $cart_total );
}
add_filter( 'woocommerce_cart_totals_order_total_html', 'matreshka_cart_total', 10, 1 );

/**
 * Format fee amounts
 */
function matreshka_fee_html( $cart_formatted_fee, $fee ) {
	return matreshka_format_price( $fee->amount );
}
add_filter( 'woocommerce_cart_totals_fee_html', 'matreshka_fee_html', 10, 2 );

/**
 * Format all wc_price() calls
 * Smart filter that formats prices only when appropriate
 */
function matreshka_wc_price_filter( $return, $price, $args ) {
	$currency = isset( $args['currency'] ) ? $args['currency'] : '';

	// wc_price() is used throughout WooCommerce (items, shipping, fees, totals,
	// discounts and order history). Rebuilding its amount HTML here keeps every
	// one of those surfaces in the same visual format.
	return '<span class="woocommerce-Price-amount amount">' . matreshka_format_price( $price, true, '', $currency ) . '</span>';
}
add_filter( 'wc_price', 'matreshka_wc_price_filter', 10, 3 );

Youez - 2016 - github.com/yon3zu
LinuXploit