|
1 | 1 | <?php |
2 | 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 | | - * This experimental snippet allows you to set the discount amount by a field that has been populated via Easy Passthrough. |
| 3 | + * We're no longer using the experimental folder for experimental snippets. 🚧 |
| 4 | + * You can now find the snippet here: |
| 5 | + * https://github.com/gravitywiz/snippet-library/blob/master/gp-ecommerce-fields/gpecf-set-discount-amount-via-gpep.php |
7 | 6 | */ |
8 | | -// Update "123" to your form ID. |
9 | | -add_filter( 'gform_pre_render_123', 'gw_set_discount_amount' ); |
10 | | -add_filter( 'gform_pre_process_123', 'gw_set_discount_amount' ); |
11 | | -add_filter( 'gform_admin_pre_render_123', 'gw_set_discount_amount' ); |
12 | | -function gw_set_discount_amount( $form ) { |
13 | | - |
14 | | - if ( current_filter() === 'gform_admin_pre_render_' . $form['id'] && GFForms::get_page() !== 'entry_detail' ) { |
15 | | - return $form; |
16 | | - } |
17 | | - |
18 | | - foreach ( $form['fields'] as &$field ) { |
19 | | - // Update "5" to your Discount field ID. |
20 | | - if ( $field->id == 3 ) { |
21 | | - // Update "6" to the field that will be populated by Easy Passthrough with the discount amount. |
22 | | - $field->discountAmount = gw_get_gpep_value( $form['id'], 6 ); |
23 | | - } |
24 | | - } |
25 | | - |
26 | | - return $form; |
27 | | -} |
28 | | - |
29 | | -function gw_get_gpep_value( $form_id, $field_id ) { |
30 | | - |
31 | | - if ( GFForms::get_page() && rgget( 'lid' ) ) { |
32 | | - $entry = GFAPI::get_entry( rgget( 'lid' ) ); |
33 | | - $field_values = $entry; |
34 | | - } else { |
35 | | - $field_values = gp_easy_passthrough()->get_field_values( $form_id ); |
36 | | - } |
37 | | - |
38 | | - return rgar( $field_values, $field_id ); |
39 | | -} |
0 commit comments