Skip to content

Instantly share code, notes, and snippets.

@ttomdewit
Created June 28, 2015 13:55
Show Gist options
  • Save ttomdewit/1d2fd43429a32a314212 to your computer and use it in GitHub Desktop.
Save ttomdewit/1d2fd43429a32a314212 to your computer and use it in GitHub Desktop.
This is at the bottom of single-claims.php, getting all data from an invoice
<?php
$invoice_fields = get_fields($fields['cla_fac_factuur'][0]);
$inv_customer = array(
'first_name' => $invoice_fields['inv_klant_voornaam'],
'last_name' => $invoice_fields['inv_klant_achternaam'],
'email' => $invoice_fields['inv_klant_email'],
'company_name' => $invoice_fields['inv_klant_bedrijfsnaam'],
'street_number' => $invoice_fields['inv_klant_straat_huisnummer'],
'zipcode' => $invoice_fields['inv_klant_postcode'],
'city' => $invoice_fields['inv_klant_woonplaats'],
'country' => $invoice_fields['inv_klant_land']
);
$inv_invoice = array(
'date' => $invoice_fields['inv_fac_datum'],
'invoice' => $invoice_fields['inv_fac_factuurnummer']
);
?>
<?php
echo "<pre>";
var_dump($fields);
echo "</pre>";
echo "<pre>";
var_dump($invoice_fields);
echo "</pre>";
?>
<div class="container">
<div class="row header">
<div class="col-md-6">
<h1><?php echo $inv_invoice['invoice']; ?></h1>
</div><!-- /col-md-6 -->
<div class="col-md-6">
<div class="logo--wrapper">
<img class="logo" src="http://www.spatotaal.nl/wp-content/uploads/2014/08/cropped-spatotaal-header-logo.png" alt="Retro-Design logo">
</div><!-- /logo--wrapper -->
</div><!-- /col-md-6 -->
</div><!-- /row -->
<hr>
<div class="row">
<div class="col-md-6">
<address>
<?php
if(!empty($inv_customer['company_name'])) {
echo $inv_customer['company_name'] . '<br>';
}
if(!empty($inv_customer['first_name'])) {
echo $inv_customer['first_name'] .' '. $inv_customer['last_name'] . '<br>';
}
if(!empty($inv_customer['street_number'])) {
echo $inv_customer['street_number'] . '<br>';
}
if(!empty($inv_customer['zipcode'])) {
echo $inv_customer['zipcode'] .', '. $inv_customer['city'] . '<br>';
}
if(!empty($inv_customer['country'])) {
echo $inv_customer['country'];
}
?>
</address>
</div><!-- /col-md-6 -->
<div class="col-md-6 text-right">
<address>
SpaTotaal<br>
Frans Erensstraat 2<br>
5921 VG, Venlo<br>
Nederland
</address>
<address>
Venlo, <?php echo $inv_invoice['date']; ?>
</address>
</div><!-- /col-md-6 -->
</div><!-- /row -->
<div class="row table-padding">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Factuur #<?php echo $inv_invoice['invoice']; ?></h3>
</div><!-- /panel-heading -->
<div class="panel-body">
<table class="table">
<thead>
<tr>
<td>Product</td>
<td class="text-right">Prijs exclusief BTW</td>
</tr>
</thead>
<tbody>
<?php
$btw = 0;
$price = 0;
for($i = 0; $i < count($invoice_fields['inv_pro_repeater']); $i++) :
$products = get_field('inv_pro_repeater', $invoice_fields['inv_pro_repeater'][$i]->ID);
var_dump($products);
$products = $products[$i];
$btw += $products['inv_pro_btw'];
$price += $products['inv_pro_prijs_inc'];
?>
<tr>
<td><?php echo $products['inv_pro_onbekend']; ?></td>
<td class="text-right">&euro;<?php echo $products['inv_pro_prijs']; ?></td>
</tr>
<?php
endfor;
?>
<tr>
<td class="text-right"><strong>BTW</strong></td>
<td class="text-right">&euro;<?php echo $btw; ?></td>
</tr>
<tr>
<td class="text-right"><strong>Totaal inclusief BTW</strong></td>
<td class="text-right">&euro;<?php echo $price; ?></td>
</tr>
</tbody>
</table><!-- /table -->
</div><!-- /panel-body -->
</div><!-- /panel panel-default -->
</div><!-- /row -->
<div class="row">
<div class="col-md-12">
<p>
Gelieve het volledige bedrag van <strong>&euro;<?php echo $price; ?></strong> binnen 30 dagen over te maken op rekeningnummer <strong>NL09INGB0684066750</strong> onder vermelding van kenmerk <strong><?php echo $inv_invoice['invoice']; ?></strong>.
</p>
</div><!-- /col-md-12 -->
</div><!-- /row -->
</div><!-- /container -->
</body>
@lukewhitehouse
Copy link

First .... get the relationship field by doing the following.

$invoices = get_field('invoices');

Then, you'll want to loop through that (it'll be an array) by doing the following

foreach($invoices as $post):

Notice how I've used $post there, thats a wordpress thing that will automatically setup the post data for a wordpress loop. After the endforeach or whatever, you'll need to use the wp_reset_postdata().

Within the foreach loop, you can then get the values for the invoice you're currently on, like so:

$field1 = get_field('field1');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment