Skip to content

Commit de9c337

Browse files
authored
gpecf-set-discount-amount-via-gpep.php: Migrated from experimental folder.
1 parent e21b59b commit de9c337

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* Gravity Perks // GP eCommerce Fields // Dynamically Set Discount Amount via Easy Passthrough
4+
* http://gravitywiz.com/documentation/gravity-forms-ecommerce-fields/
5+
*
6+
* Experimental Snippet 🧪
7+
*
8+
* This experimental snippet allows you to set the discount amount by a field that has been populated via Easy Passthrough.
9+
*/
10+
// Update "123" to your form ID.
11+
add_filter( 'gform_pre_render_123', 'gw_set_discount_amount' );
12+
add_filter( 'gform_pre_process_123', 'gw_set_discount_amount' );
13+
add_filter( 'gform_admin_pre_render_123', 'gw_set_discount_amount' );
14+
function gw_set_discount_amount( $form ) {
15+
16+
if ( current_filter() === 'gform_admin_pre_render_' . $form['id'] && GFForms::get_page() !== 'entry_detail' ) {
17+
return $form;
18+
}
19+
20+
foreach ( $form['fields'] as &$field ) {
21+
// Update "5" to your Discount field ID.
22+
if ( $field->id == 3 ) {
23+
// Update "6" to the field that will be populated by Easy Passthrough with the discount amount.
24+
$field->discountAmount = gw_get_gpep_value( $form['id'], 6 );
25+
}
26+
}
27+
28+
return $form;
29+
}
30+
31+
function gw_get_gpep_value( $form_id, $field_id ) {
32+
33+
if ( GFForms::get_page() && rgget( 'lid' ) ) {
34+
$entry = GFAPI::get_entry( rgget( 'lid' ) );
35+
$field_values = $entry;
36+
} else {
37+
$field_values = gp_easy_passthrough()->get_field_values( $form_id );
38+
}
39+
40+
return rgar( $field_values, $field_id );
41+
}

0 commit comments

Comments
 (0)