Skip to content

Instantly share code, notes, and snippets.

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 jetsloth/ef22906f91059202d30c0a60a9e9af63 to your computer and use it in GitHub Desktop.
Save jetsloth/ef22906f91059202d30c0a60a9e9af63 to your computer and use it in GitHub Desktop.
Gravity Perks eCommerce Fields Order Summary markup customised to include Image Choices display
<?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();
$form_id = rgar($form, "id");
?>
<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'] . ' ' . $product['price'] ); ?>
</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 ):
$class = $index == count( $product['options'] ) - 1 ? '.last-child' : '';
$option_field = RGFormsModel::get_field( $form_id, $option['id'] );
?>
<li style="<?php gp_ecommerce_fields()->style( ".order-summary/.product-options/li{$class}" ); ?>"><?php
if ( function_exists('gf_image_choices') && property_exists($option_field, 'imageChoices_enableImages') && !empty($option_field->imageChoices_enableImages) ) {
echo $option['option_name'];
$option_image_src = gf_image_choices()->get_choice_image_src( $option_field, $option['option_name'], 'text' );
$option_image = gf_image_choices()->get_choice_image_item_markup( $option_image_src );
$option_image = str_replace( 'margin: 0 10px 20px;', '', $option_image );
$option_image = str_replace( 'display: inline-block; vertical-align: top; text-align: center;', 'display: block; vertical-align: top; text-align: left;', $option_image );
echo $option_image;
}
else {
echo $option['option_label'];
}
?></li>
<?php
endforeach;
endif;
$field_total = floatval( $product['quantity'] ) * $price;
$product_total = floatval( $product['quantity'] ) * GFCommon::to_number( $product['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( $product['price'], $entry['currency'] ); ?>
<ul style="<?php gp_ecommerce_fields()->style( '.order-summary/.product-options' ); ?>">
<?php
if ( is_array( rgar( $product, 'options' ) ) ):
foreach ( $product['options'] as $index => $option ):
$class = $index == count( $product['options'] ) - 1 ? '.last-child' : '';
$option_field = RGFormsModel::get_field( $form_id, $option['id'] );
?>
<li style="<?php gp_ecommerce_fields()->style( ".order-summary/.product-options/li{$class}" ); ?> list-style-type: none !important;"><?php
if ( function_exists('gf_image_choices') && property_exists($option_field, 'imageChoices_enableImages') && !empty($option_field->imageChoices_enableImages) ) {
echo '<div style="margin-bottom:85px;">' . GFCommon::to_money( $option['price'], $entry['currency'] ) . '</div>';
}
else {
echo GFCommon::to_money( $option['price'], $entry['currency'] );
}
?></li>
<?php
endforeach;
endif;
?>
</ul>
</td>
<td style="<?php gp_ecommerce_fields()->style( '.order-summary/tbody/tr/td.column-4' ); ?>"><?php echo GFCommon::to_money( $product_total, $entry['currency'] ); ?>
<ul style="<?php gp_ecommerce_fields()->style( '.order-summary/.product-options' ); ?>">
<?php
if ( is_array( rgar( $product, 'options' ) ) ):
foreach ( $product['options'] as $index => $option ):
$class = $index == count( $product['options'] ) - 1 ? '.last-child' : '';
$option_total = floatval( $product['quantity'] ) * $option['price'];
$option_field = RGFormsModel::get_field( $form_id, $option['id'] );
?>
<li style="<?php gp_ecommerce_fields()->style( ".order-summary/.product-options/li{$class}" ); ?> list-style-type: none !important;"><?php
if ( function_exists('gf_image_choices') && property_exists($option_field, 'imageChoices_enableImages') && !empty($option_field->imageChoices_enableImages) ) {
echo '<div style="margin-bottom:85px;">' . GFCommon::to_money( $option_total, $entry['currency'] ) . '</div>';
}
else {
echo GFCommon::to_money( $option_total, $entry['currency'] );
}
?></li>
<?php
endforeach;
endif;
?>
</ul>
</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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment