Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 3 additions & 36 deletions experimental/gpecf-set-discount-amount-via-gpep.php
Original file line number Diff line number Diff line change
@@ -1,39 +1,6 @@
<?php
/**
* Gravity Perks // GP eCommerce Fields // Dynamically Set Discount Amount via Easy Passthrough
* http://gravitywiz.com/documentation/gravity-forms-ecommerce-fields/
*
* This experimental snippet allows you to set the discount amount by a field that has been populated via Easy Passthrough.
* We're no longer using the experimental folder for experimental snippets. 🚧
* You can now find the snippet here:
* https://github.com/gravitywiz/snippet-library/blob/master/gp-ecommerce-fields/gpecf-set-discount-amount-via-gpep.php
*/
// Update "123" to your form ID.
add_filter( 'gform_pre_render_123', 'gw_set_discount_amount' );
add_filter( 'gform_pre_process_123', 'gw_set_discount_amount' );
add_filter( 'gform_admin_pre_render_123', 'gw_set_discount_amount' );
function gw_set_discount_amount( $form ) {

if ( current_filter() === 'gform_admin_pre_render_' . $form['id'] && GFForms::get_page() !== 'entry_detail' ) {
return $form;
}

foreach ( $form['fields'] as &$field ) {
// Update "5" to your Discount field ID.
if ( $field->id == 3 ) {
// Update "6" to the field that will be populated by Easy Passthrough with the discount amount.
$field->discountAmount = gw_get_gpep_value( $form['id'], 6 );
}
}

return $form;
}

function gw_get_gpep_value( $form_id, $field_id ) {

if ( GFForms::get_page() && rgget( 'lid' ) ) {
$entry = GFAPI::get_entry( rgget( 'lid' ) );
$field_values = $entry;
} else {
$field_values = gp_easy_passthrough()->get_field_values( $form_id );
}

return rgar( $field_values, $field_id );
}
Loading