Forked from spivurno/gp-ecommerce-fields-consolidate-discounts.php
Created
March 28, 2020 05:49
-
-
Save phillipwilhelm/6aaa79b3c1d3dd069ef3c0acde4d0f72 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