<button class="pay-button" id="open-button">
Pay
<?php
$total=0;
foreach ($_invoices as $_invoice): ?>
<?php if($_invoice->getData('status') == 0) :
$total = $total+$_invoice->getGrandTotal(); ?>
<?php endif;?>
<?php endforeach;
echo $total;
?>
</button>