Created
February 18, 2019 01:21
-
-
Save spivurno/18c9a470db892ecaa12cf2340fbba6aa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Gravity Perks // eCommerce Fields // Consolidate Separate Discount Line Items into a Single Discounts Line Item | |
* http://gravitywiz.com/documentation/gravity-forms-ecommerce-fields/ | |
* | |
* 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; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👉 This Gist has been migrated to the Gravity Wiz Snippet Library:
https://github.com/gravitywiz/snippet-library/blob/master/gp-ecommerce-fields/gpecf-consolidate-discounts.php