Dynamically Set Discount Amount

Code

Filename: gpecf-dynamically-set-discount.php

<?php
/**
 * Gravity Perks // GP eCommerce Fields // Dynamically Set Discount Amount
 * https://gravitywiz.com/documentation/gravity-forms-ecommerce-fields/
 */
// Update "123" to your form ID.
add_filter( 'gform_pre_render_123', 'gw_set_discount_amount' );
add_filter( 'gform_pre_validation_123', 'gw_set_discount_amount' );
add_filter( 'gform_pre_submission_filter_123', 'gw_set_discount_amount' );
function gw_set_discount_amount( $form ) {

	foreach ( $form['fields'] as &$field ) {

		// Update "2" to your Discount field ID.
		if ( $field->id == 2 ) {
			$field->discountAmount = 50;
		}
	}

	return $form;
}

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.