    
<?php
$args = array(
    'limit' => -1, 
    'status' => 'publish',
);
    
$products = wc_get_products($args); 
// 33
function truncate_text($text, $length = 60) {
    if (strlen($text) > $length) {
        return substr($text, 0, $length) . '...';
    }
    return $text;
}

if (!empty($products)) : ?>
    <div class="badania__wrapper">
        <?php foreach ($products as $product) : 
            $product_id = $product->get_id();
            $product_title = truncate_text($product->get_name());
            // $product_price = $product->get_price();
            $product_price = get_post_meta($product_id, '_custom_product_full_price', true);
            $formatted_price = number_format((float)$product_price , 2, ',', '');

            if (substr($formatted_price, -3) === ',00') {
                $formatted_price = number_format((float)$product_price , 0, ',', '');
        }
        ?>
            <div class="badanie__el" data-product-id="<?php echo esc_attr($product_id); ?>">
                <div class="badanie__title"><?php echo esc_html($product_title); ?></div>
                <div class="badanie__price">
                    <?php echo wp_kses_post($formatted_price); ?> zł
                    <div class="badanie__circle"></div>
                </div>
            </div>
        <?php endforeach; ?>
    </div>
<?php endif; ?>

<script>
	document.querySelectorAll('.badanie__title').forEach(function(element) {
    const regex = /\(([^)]+)\)/; 
    const match = element.textContent.match(regex);
    
    if (match) {
        const span = document.createElement('span');
        span.className = 'brackets__small';
        span.textContent = match[0]; 
        
        element.innerHTML = element.innerHTML.replace(regex, span.outerHTML);
    }
});

</script>