Consolidate Separate Discount Line Items into a Single Discounts Line Item
Default: https://gwiz.io/2IiPALf w/ Snippet: https://gwiz.io/2Itfyfo
Instructions
Code
Filename: gpecf-consolidate-discounts.php
<?php
/**
* Gravity Perks // eCommerce Fields // Consolidate Separate Discount Line Items into a Single Discounts Line Item
* https://gravitywiz.com/documentation/gravity-forms-ecommerce-fields/
*
* Instruction Video: https://www.loom.com/share/8c00449041864d30833d334274947484
*
* Default: https://gwiz.io/2IiPALf
* w/ Snippet: https://gwiz.io/2Itfyfo
*/
// Update "123" to your form ID - or - remove "_123" to apply to all forms.
add_filter( 'gpecf_order_summary_123', function( $summary ) {
if ( empty( $summary['discounts'] ) ) {
return $summary;
}
$consolidated_discount = $summary['discounts'][0];
$consolidated_discount['name'] = 'Discounts';
$consolidated_discount['price'] = 0;
foreach ( $summary['discounts'] as $discount ) {
$consolidated_discount['price'] += $discount['price'];
}
$summary['discounts'] = array( $consolidated_discount );
return $summary;
} );