Skip to content

Instantly share code, notes, and snippets.

@dancameron
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dancameron/e4b47aabe3f460d8b20f to your computer and use it in GitHub Desktop.
Save dancameron/e4b47aabe3f460d8b20f to your computer and use it in GitHub Desktop.
HTML Table Filter Example (using client's HTML)
<?php
function si_item_list_table( $original_table, $line_items, $data ) {
$subtotal = 0;
$tax = 0;
$total = 0;
if ( isset( $data['invoice'] ) && is_a( $data['invoice'], 'SI_Invoice' ) ) {
$subtotal = si_get_invoice_subtotal( $data['invoice']->get_ID() );
$tax = si_get_invoice_taxes_total( $data['invoice']->get_ID() );
$total = si_get_invoice_total( $data['invoice']->get_ID() );
}
elseif ( isset( $data['estimate'] ) && is_a( $data['estimate'], 'SI_Estimate' ) ) {
$subtotal = si_get_estimate_subtotal( $data['estimate']->get_ID() );
$tax = si_get_estimate_taxes_total( $data['estimate']->get_ID() );
$total = si_get_estimate_total( $data['estimate']->get_ID() );
}
ob_start(); ?>
<table border="0" width="100%" cellpadding="0" cellspacing="0" bgcolor="ffffff">
<tr>
<td align="center">
<table border="0" align="center" width="590" cellpadding="0" cellspacing="0" class="container590 bg_color">
<tr bgcolor="ffffff">
<td align="left" mc:edit="header2" style="color: #26313c; font-size: 12px; font-family: 'Open Sans', sans-serif; mso-line-height-rule: exactly; line-height: 24px; border-bottom: solid 3px #eaedf0;" class="title_color"><!-- ======= text ======= -->
<div style="line-height: 24px;">Omschrijving</div>
</td>
<td width="95" align="center" mc:edit="header3" style="color: #26313c; font-size: 12px; font-family: 'Open Sans', sans-serif; mso-line-height-rule: exactly; line-height: 24px; border-bottom: solid 3px #eaedf0;" class="title_color">
<!-- ======= text ======= -->
<div style="line-height: 24px;">
Quantity
</div>
</td>
<td width="95" align="center" mc:edit="header4" style="color: #26313c; font-size: 12px; font-family: 'Open Sans', sans-serif; mso-line-height-rule: exactly; line-height: 24px; border-bottom: solid 3px #eaedf0;" class="title_color"><!-- ======= text ======= -->
<div style="line-height: 24px;">Price</div>
</td>
</tr>
<tr><td height="10" style="font-size: 10px; line-height: 10px;">&nbsp;</td></tr>
<?php foreach ( $line_items as $position => $data ):
// This is were the loop is for all the items.
// Variables for each line item info
$desc = ( isset( $data['desc'] ) ) ? $data['desc'] : '' ;
$rate = ( isset( $data['rate'] ) ) ? $data['rate'] : 0 ;
$qty = ( isset( $data['qty'] ) ) ? $data['qty'] : 0 ;
$tax = ( isset( $data['tax'] ) ) ? $data['tax'] : 0 ;
$total = ( isset( $data['total'] ) ) ? $data['total'] : 0 ; ?>
<tr>
<td valign="top">
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr><td height="5" style="font-size: 5px; line-height: 5px;">&nbsp;</td></tr>
<tr>
<td align="left" mc:edit="itemtitle1" style="color: #26313c; font-size: 13px; font-family: 'Open Sans', sans-serif; font-weight: 700; letter-spacing: 1px; mso-line-height-rule: exactly; line-height: 22px;" class="title_color">
<!-- ======= text ======= -->
<div style="line-height: 22px;">
<?php
if ( isset( $data['type'] ) && $data['type'] ) {
$term = get_term( $data['type'], SI_Estimate::LINE_ITEM_TAXONOMY );
if ( !is_wp_error( $term ) && $term ) {
printf( '<span class="line_item_type tooltip" title="%s"></span>', esc_attr__( $term->name ) );
}
} ?>
</div>
</td>
</tr>
<tr><td height="5" style="font-size: 5px; line-height: 5px;">&nbsp;</td></tr>
<tr>
<td align="left" mc:edit="itemtext1" style="color: #919399; font-size: 13px; font-family: 'Open Sans', sans-serif; mso-line-height-rule: exactly; line-height: 22px;" class="title_color"><!-- ======= text ======= -->
<div style="line-height: 22px;"><?php echo apply_filters( 'the_content', $desc ) ?></div>
</td>
</tr>
</table>
</td>
<td align="center" mc:edit="itemtitle2" style="color: #26313c; font-size: 13px; font-family: 'Open Sans', sans-serif; mso-line-height-rule: exactly; line-height: 22px;" class="title_color">
<!-- ======= text ======= -->
<div style="line-height: 22px;">
<?php esc_attr_e( $qty ) ?>
</div>
</td>
<td align="center" mc:edit="itemtitle3" style="color: #26313c; font-size: 13px; font-family: 'Open Sans', sans-serif; mso-line-height-rule: exactly; line-height: 22px;" class="title_color">
<!-- ======= text ======= -->
<div style="line-height: 22px;">
<?php sa_formatted_money( $rate ) ?>
</div>
</td>
</tr>
<tr><td height="10" style="font-size: 10px; line-height: 10px;">&nbsp;</td></tr>
<tr bgcolor="e8eaec"><td colspan="4" height="1" style="font-size: 1px; line-height: 1px;">&nbsp;</td></tr>
<tr><td height="10" style="font-size: 10px; line-height: 10px;">&nbsp;</td></tr>
<?php endforeach ?>
<tr><td height="30" style="font-size: 30px; line-height: 30px;">&nbsp;</td></tr>
<tr>
<td colspan="4">
<table border="0" align="right" width="190" cellpadding="6" cellspacing="0">
<tr>
<td mc:edit="abouttext25" align="left" height="" valign="middle" style="color: #26313c; font-size: 12px; font-family: 'Open sans', sans-serif; mso-line-height-rule: exactly; line-height: 26px;">
Subtotaal
</td>
<td mc:edit="abouttext26" align="right" height="" valign="middle" style="color: #26313c; font-size: 14px; font-family: 'Open sans', sans-serif; mso-line-height-rule: exactly; line-height: 26px;">
<?php sa_formatted_money( $subtotal ) ?>
</td>
</tr>
<tr>
<td mc:edit="abouttext27" align="left" height="" valign="middle" style="color: #26313c; font-size: 14px; font-family: 'Open sans', sans-serif; mso-line-height-rule: exactly; line-height: 26px;">
BTW
</td>
<td mc:edit="abouttext28" align="right" height="" valign="middle" style="color: #26313c; font-size: 14px; font-family: 'Open sans', sans-serif; mso-line-height-rule: exactly; line-height: 26px;">
<?php sa_formatted_money( $tax ) ?>
</td>
</tr>
<tr bgcolor="ffffff">
<td mc:edit="abouttext29" align="left" height="" valign="middle" style="color: #26313c; font-size: 14px; font-family: 'Open sans', sans-serif; font-weight: 700; mso-line-height-rule: exactly; line-height: 26px;">
Total
</td>
<td mc:edit="abouttext30" align="right" height="" valign="middle" style="color: #26313c; font-size: 14px; font-family: 'Open sans', sans-serif; mso-line-height-rule: exactly; line-height: 26px;">
<?php sa_formatted_money( $total ) ?>
</td>
</tr>
</table>
</td>
</tr>
<tr><td height="80" style="font-size: 80px; line-height: 80px;">&nbsp;</td></tr>
</table>
</td>
</tr>
</table>
<?
return ob_get_clean();
}
add_filter( 'shortcode_line_item_table', 'si_item_list_table', 10, 4 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment