gpecf-customize-order-summary-markup.php
Instructions
See “Where do I put snippets?” in our documentation for installation instructions.
Code
Filename: gpecf-customize-order-summary-markup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
add_filter( 'gpecf_order_sumary_markup', 'get_custom_order_summary_markup', 10, 6 );
function get_custom_order_summary_markup( $markup, $order, $form, $entry, $order_summary, $labels ) {
ob_start();
?>
<table class="gpecf-order-summary" cellspacing="0" width="100%" style="<?php gp_ecommerce_fields()->style( '.order-summary' ); ?>">
<thead>
<tr>
<th scope="col" style="<?php gp_ecommerce_fields()->style( '.order-summary/thead/th.column-1' ); ?>"><?php echo $labels['product']; ?></th>
<th scope="col" style="<?php gp_ecommerce_fields()->style( '.order-summary/thead/th.column-2' ); ?>"><?php echo $labels['quantity']; ?></th>
<th scope="col" style="<?php gp_ecommerce_fields()->style( '.order-summary/thead/th.column-3' ); ?>"><?php echo $labels['unit_price']; ?></th>
<th scope="col" style="<?php gp_ecommerce_fields()->style( '.order-summary/thead/th.column-4' ); ?>"><?php echo $labels['price']; ?></th>
</tr>
</thead>
<tbody>
<?php
foreach ( $order['products'] as $product ) :
if ( empty( $product['name'] ) || gp_ecommerce_fields()->is_ecommerce_product( $product ) ) {
continue;
}
?>
<tr style="<?php gp_ecommerce_fields()->style( '.order-summary/tbody/tr' ); ?>">
<td style="<?php gp_ecommerce_fields()->style( '.order-summary/tbody/tr/td.column-1' ); ?>">
<div style="<?php gp_ecommerce_fields()->style( '.order-summary/.product-name' ); ?>">
<?php echo esc_html( $product['name'] ); ?>
</div>
<ul style="<?php gp_ecommerce_fields()->style( '.order-summary/.product-options' ); ?>">
<?php
$price = GFCommon::to_number( $product['price'] );
if ( is_array( rgar( $product, 'options' ) ) ) :
foreach ( $product['options'] as $index => $option ) :
$price += GFCommon::to_number( $option['price'] );
$class = $index == count( $product['options'] ) - 1 ? '.last-child' : '';
?>
<li style="<?php gp_ecommerce_fields()->style( ".order-summary/.product-options/li{$class}" ); ?>"><?php echo $option['option_label']; ?></li>
<?php
endforeach;
endif;
$field_total = floatval( $product['quantity'] ) * $price;
?>
</ul>
</td>
<td style="<?php gp_ecommerce_fields()->style( '.order-summary/tbody/tr/td.column-2' ); ?>"><?php echo esc_html( $product['quantity'] ); ?></td>
<td style="<?php gp_ecommerce_fields()->style( '.order-summary/tbody/tr/td.column-3' ); ?>"><?php echo GFCommon::to_money( $price, $entry['currency'] ); ?></td>
<td style="<?php gp_ecommerce_fields()->style( '.order-summary/tbody/tr/td.column-4' ); ?>"><?php echo GFCommon::to_money( $field_total, $entry['currency'] ); ?></td>
</tr>
<?php
endforeach;
?>
</tbody>
<tfoot style="<?php gp_ecommerce_fields()->style( '.order-summary/tfoot' ); ?>">
<?php foreach ( gp_ecommerce_fields()->get_order_summary( $order, $form, $entry ) as $index => $group ) : ?>
<?php
foreach ( $group as $item ) :
$class = rgar( $item, 'class' ) ? '.' . rgar( $item, 'class' ) : '';
?>
<tr style="<?php gp_ecommerce_fields()->style( '.order-summary/tfoot/tr' . $class ); ?>">
<?php if ( $index === 0 ) : ?>
<td style="<?php gp_ecommerce_fields()->style( '.order-summary/tfoot/tr/td.empty' ); ?>" colspan="2" rowspan="<?php echo gp_ecommerce_fields()->get_order_summary_item_count( $order_summary ); ?>"></td>
<?php endif; ?>
<td style="<?php gp_ecommerce_fields()->style( ".order-summary/tfoot/{$class}/td.column-3" ); ?>"><?php echo $item['name']; ?></td>
<td style="<?php gp_ecommerce_fields()->style( ".order-summary/tfoot/{$class}/td.column-4" ); ?>"><?php echo GFCommon::to_money( $item['price'], $entry['currency'] ); ?></td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
</tfoot>
</table>
<?php
return ob_get_clean();
}
Need explanation. Is it how I will be able to edit the english terms to french in the order summary?
Hi,
Good question. This snippet doesn’t have any English text to translate itself. The labels (Product, Quantity, Price, etc.) come from GP eCommerce Fields’ own settings, not this code. To change them to French, you’d translate those strings using a plugin like WPML or Loco Translate. Feel free to reach out to us via the support form if you need further assistance with this.
Best,
This works and shows up with I use {order_summary} in an email as you can see in my Estimator. However, it does not modify the order summary that is shown in the PDF generated by Gravity PDF.
Hi Michael,
You’re right, the snippet doesn’t appear to work on the order summary generated by GravityPDF. I will forward this to our product manager to see if support can be added for this. We’ll update the comment when there is more information on this.
Best,