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;
} );

Leave a Reply

Your email address will not be published. Required fields are marked *

  • Trouble installing this snippet? See our troubleshooting tips.
  • Need to include code? Create a gist and link to it in your comment.
  • Reporting a bug? Provide a URL where this issue can be recreated.

By commenting, I understand that I may receive emails related to Gravity Wiz and can unsubscribe at any time.