Access ACF Repeater fields in code block

Dear community, I would like to ask for help.

I am building a Pricing Table with ACF repeater, which is perfectly fine, until I want to do some VAT calculations between sub_fields. Is it possible to access current ACF repeater row sub_fields from code block?

I tried to use the basic get_sub_field because I am already in ACF repeater, but without a luck. If I use the whole ACF repeater loop in code block, I get all repeater rows which I dont want.

Mine code:

        // Získání hodnoty z pole fve_price
        $fve_price = get_sub_field('fve_price');
        // Výpočet DPH (12% z ceny s DPH)
        $dph = $fve_price * 0.12;
        // Výpočet ceny bez DPH
        $price_excluding_vat = $fve_price - $dph;
        // Formátování čísel pro výpis
        $formatted_fve_price = number_format($fve_price, 0, '.', ' ');
        $formatted_price_excluding_vat = number_format($price_excluding_vat, 0, '.', ' ');
        $formatted_dph = number_format($dph, 0, '.', ' ');

        // Výpis ceny s DPH
        echo "Cena s DPH: {$formatted_fve_price} KÄŤ<br>";

        // Výpis ceny bez DPH
        echo "Cena bez DPH: {$formatted_price_excluding_vat} KÄŤ<br>";
        // Výpis DPH
        echo "DPH: {$formatted_dph} KÄŤ<br>";

        // Získání hodnoty z pole fve_dotace
        $fve_dotace = get_sub_field('fve_dotace');
        // Výpočet ceny po odečtení dotace
        $price_after_subsidy = $fve_price - $fve_dotace;
        $formatted_price_after_subsidy = number_format($price_after_subsidy, 0, '.', ' ');

        // Výpis ceny po odečtení dotace
        echo "Cena po odeÄŤtenĂ­ dotace: {$formatted_price_after_subsidy} KÄŤ<br><br>";

Can you try with the line changed to

fve_price = get_sub_field('fve_price', get_the_id());

Cheers

Patric

Hello Patric, thanks for the idea. However, this doesn’t helped. The returned ID is ID of current post.

@timmse I am sorry for tagging you, but I am lost ─ don’t you know if it is possible to access the ACF repeater data from Code block inside ACF query?

Thanks for your time. Aleš

Solved with parse dynamic data option in new version of Bricks.

<?php
// Tento kód by měl být uvnitř existující smyčky opakovače v Bricks builderu
// Získání hodnoty z pole fve_price
$fve_price = "{acf_fve_tabulky_fve_price}";
$dph = $fve_price * 0.12;
$price_excluding_vat = $fve_price - $dph;

// Formátování čísel pro výpis
$formatted_fve_price = number_format($fve_price, 0, '.', ' ');
$formatted_price_excluding_vat = number_format($price_excluding_vat, 0, '.', ' ');
$formatted_dph = number_format($dph, 0, '.', ' ');

// Získání hodnoty z pole fve_dotace a výpočet
$fve_dotace = "{acf_fve_tabulky_fve_dotace}";
$price_after_subsidy = $fve_price - $fve_dotace;
$formatted_price_after_subsidy = number_format($price_after_subsidy, 0, '.', ' ');
$formatted_fve_dotace = number_format($fve_dotace, 0, '.', ' ');

// Výpis v požadovaném pořadí
echo "<span class='price_novat'>Cena (bez DPH): {$formatted_price_excluding_vat} KÄŤ</span><br>";
echo "<span class='price_vat'>DPH (12%): {$formatted_dph} KÄŤ</span><br>";
echo "<span class='price_wvat'>Cena s DPH: {$formatted_fve_price} KÄŤ</span><br>";

// Výpis výše dotace
echo "<span class='price_subsidy'>Dotace: {$formatted_fve_dotace} KÄŤ</span><br>";
echo "<span class='price_final'>Cena po odeÄŤtenĂ­ dotace: {$formatted_price_after_subsidy} KÄŤ</span>";
?>

1 Like