-
-
Save richardW8k/9bb37e4f955c4d8c68e0 to your computer and use it in GitHub Desktop.
<?php | |
class RW_GF_Total_Field_Logic { | |
public function __construct() { | |
add_action( 'init', array( $this, 'init' ) ); | |
} | |
function init() { | |
if ( ! property_exists( 'GFForms', 'version' ) || ! version_compare( GFForms::$version, '1.9', '>=' ) ) { | |
return; | |
} | |
add_filter( 'gform_field_content', array( $this, 'maybe_add_logic_event' ), 10, 2 ); | |
add_filter( 'gform_admin_pre_render', array( $this, 'enable_total_in_conditional_logic' ) ); | |
} | |
function maybe_add_logic_event( $content, $field ) { | |
if ( $field->type != 'total' ) { | |
return $content; | |
} | |
$logic_event = $field->get_conditional_logic_event( 'change' ); | |
return ! empty( $logic_event ) ? str_replace( "gform_hidden'", "gform_hidden' value='0' {$logic_event}", $content ) : $content; | |
} | |
function enable_total_in_conditional_logic( $form ) { | |
if ( GFCommon::is_entry_detail() ) { | |
return $form; | |
} | |
?> | |
<script type='text/javascript'> | |
gform.addFilter('gform_is_conditional_logic_field', function (isConditionalLogicField, field) { | |
return field.type == 'total' ? true : isConditionalLogicField; | |
}); | |
gform.addFilter('gform_conditional_logic_operators', function (operators, objectType, fieldId) { | |
targetField = GetFieldById(fieldId); | |
if (targetField && targetField['type'] == 'total') { | |
operators = {'>': 'greaterThan', '<': 'lessThan'}; | |
} | |
return operators; | |
}); | |
</script> | |
<?php | |
return $form; | |
} | |
} | |
new RW_GF_Total_Field_Logic(); |
Are you running the latest version of the snippet, the function for the gform_conditional_logic_operators hook was updated to resolve this issue in December.
Thanks for the nudge to update, Richard. That worked.
It appears that when using this solution and using the "Form total greater than" conditional logic the payment details are not save with the lead entry.
Screenshot of entry without any conditional logic, or even conditional logic, but not the "Form total" logic: http://upload.uprise.nl/XRIb
Screenshot of entry with "Form total greater than 0": http://upload.uprise.nl/17e9f
And it isn't just that it doesn't display the payment details, but they're not even stored in the database (http://upload.uprise.nl/417a).
When doing some digging it appears that the "validation" method (for "gform_validation" filter), called on line 60 in includes/addon/class-gf-payment-addon.php, isn't executed. Why, I really can't figure out, but it seems something's going wrong there :)
I'm noticing that this alters the Pricing » Option field type and removes the ability to have checkboxes. Specifically, it replaces an Option's default field types (Drop Down, Checkboxes, Radio Buttons) to new ones (Single Product, Drop Down, Radio Buttons, User Defined Price, Hidden, Calculation).
Any idea how to circumvent this but still use this function to show the total field?