So I'm making a WP-template using ACF, and in it there's a table
. Within this table want to add some results. Now, to get the total amount I have to add the value of all $price
, which will vary for each since it is in a repeater field
.
So how do I make dynamic variables and then add the value of them into a new variable?
my code:
<?php if (get_sub_field('offer_pr_ob')): while(has_sub_field('offer_pr_ob')):
$qt = floatval(get_sub_field('offer_pr_ob_qt'));
$hrs = floatval(get_sub_field('offer_pr_ob_hrs'));
$hrsRt = floatval(get_sub_field('offer_pr_ob_hrs-rt'));
$hrsTot = $qt * $hrs;
$price = $hrsTot * $hrsRt;
$priceVat = $price * 1.25;
$priceTot = $price + $price; <-- this just outputs the value of
the latest $price, e.g. "price*2" -->
?>
<tr class="pricingObject">
<td><?php the_sub_field('offer_pr_ob_typ'); ?></td>
<td><?php echo $qt; ?></td>
<td><?php the_sub_field('offer_pr_ob_hrs-rt'); ?>.-</td>
<td>
<?php echo $hrs; ?>/<?php the_sub_field('offer_pr_ob_per'); ?></td>
<td>
<?php echo $hrsTot;?>h/år</td>
<td><?php echo $price;.-</td>
<td><?php echo $priceVat;?>.-</td>
</tr>
<?php endwhile; endif;?>
<tr class="pricingResult">
<th>Total årskostnad</th>
<th> </th>
<th> </th>
<th> </th>
<th> </th>
<th><?php echo $priceTot; ?>.-</th>
<th>10 790 000.-</th>
</tr>
</table>
</div>
<?php endwhile; endif; ?>