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
41 changes: 41 additions & 0 deletions gp-ecommerce-fields/gpecf-set-discount-amount-via-gpep.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Gravity Perks // GP eCommerce Fields // Dynamically Set Discount Amount via Easy Passthrough
* https://gravitywiz.com/documentation/gravity-forms-ecommerce-fields/
*
* Experimental Snippet 🧪
*
* This experimental snippet allows you to set the discount amount by a field that has been populated via Easy Passthrough.
*/
// 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