Skip to content

Instantly share code, notes, and snippets.

@Idealien
Created September 26, 2018 01:49
Show Gist options
  • Save Idealien/8fb26ba57600d26d54b4b3ce8126035c to your computer and use it in GitHub Desktop.
Save Idealien/8fb26ba57600d26d54b4b3ce8126035c to your computer and use it in GitHub Desktop.
Example of post-workflow step calculations
<?php
add_action( 'gravityflow_post_webhook', 'sh_action_gravityflow_post_webhook', 10, 4 );
function sh_action_gravityflow_post_webhook( $response, $args, $entry, $current_step ) {
//Replace step ID and fields for calculation to match your use case.
if ( $current_step->get_id() == 77 && is_numeric( $entry['3'] ) && is_numeric( $entry['16'] ) ) {
$entry['14'] = round( $entry['3'] * $entry['16'], 2);
$result = GFAPI::update_entry( $entry );
}
}
@kamyarazar
Copy link

Hi
First of all, Thank You Very Much for write and share this code, case i search it a lot for finding this code, and i really needed.
I need it for calculation (for example) field (1) with field (2) to make field (3) value.
But... i have 2 questions:

1- If i add "outgoing webhook" step without any URL and field value, it will make problem for me or my hosting services? case it will return (WP error).

2- How can i calculate field (3), when a "gravityflow formconnector [update entry or update field]" step is my choice?

If you answer me, i will really Thank you.

@Idealien
Copy link
Author

Hello - You might be better served by submitting a support ticket to https://gravityflow.io/support/ or reviewing their docs at https://docs.gravityflow.io/article/95-gravityflowwebhookargs

1 - Yes the outgoing webhook step requires a URL. They use wp_remote_request functions of WP core that you could filter/modify if needed.

2 - Probably by using a custom merge tag (Gravity Forms docs) in the field mapping of the Form Connector step.

@kamyarazar
Copy link

Thank you very much for your fast answer!
Yes i can submit a support ticket and if its necessary ill do, but i was think maybe it can be someone else questions to.

Actually when i put number with update entry and update field step in field (1) and field (2), field (3) (calculation field) doesn't change and its still "0". and that's why i search for codes.

I find a helpful post in here, and i changed all [new_entry] to [update_entry], and this is result, but it doesn't work and return fatal error:

add_filter( 'gravityflowformconnector_update_entry', 'sh_gravityflowconnector_adjust_update_entry', 10, 5); function sh_gravityflowconnector_adjust_update_entry( $response, $args, $entry, $current_step ) { //Replace step ID and fields for calculation to match your use case. if ( $current_step->get_id() == 507 && is_numeric( $entry['1'] ) && is_numeric( $entry['2'] ) ) { $entry['3'] = round( $entry['1'] + $entry['2'], 0); $result = GFAPI::update_entry( $entry ); } }

Can you help me how should it be to works please?
What's the correct add_action & function should i use for update entry step?

Thanks a Lot

image

@Idealien
Copy link
Author

Your snippet is modifying the $entry which is not part of $response which is what the filter returns back to the rest of Gravity Flow for processing. You use the GFAPI to update the entry, but it is most likely that Gravity Flow would use the values in $response after your filter runs to update the entry. The doc you linked to provides good examples of how your code should be structured or you may want to review https://developer.wordpress.org/reference/functions/add_filter/ as both issues are concepts that the core of WP approach to hooks covers.

  • Modify $result instead of $entry
  • Ensure your filter returns $result instead of using the GFAPI.
  • Your goal seems to be unrelated to the filter of this snippet. Vendor support might be a better place to ask follow-ups.

@kamyarazar
Copy link

kamyarazar commented Feb 16, 2021

Hello again
Thank you very much
I was submit in there and if it will be solved, ill share it for sure!
If you dont like my comments to be here, im sory for that an i can delete them quiekly
Thanks again and Good Bye.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment