GravityForms has a simple action hook that can be used after submission
add_action( 'gform_after_submission', 'my_function', 10, 2 );
my_function is any user-defined function where the call reaches if the action hook is found in functions.php
StickyList, an add-on built on GravityForms also provides an action hook that can be used after the form is submitted. It is here below
add_action("gform_after_submission", array($this, "post_edit_entry"),
10, 2);
My question is, how does one use the my_function to the StickyList action hook which hasn't specified/documented how to use this action hook. I don't know what the array is doing as a second argument and how to get the call to reach my user defined function once this action_hook is found in functions.php.
The stickyList add_action hook after editing entry I found that worked was the following. Thanks Samvel for your help.
add_action('stickylist_entry_edited','my_function', 10, 2 );
Related
I am trying to fire a custom function when a credit card error occurs in the WooCommerce checkout flow.
I seem to be able to get standard woo errors by using but it seems that the stripe plugin does not us woocommerce_add_error
add_filter( 'woocommerce_add_error', 'my_woocommerce_add_error' );
I found the following hook in the WooCommerce Stripe documentation, but I can't seem to get it to work with add_action
wc_gateway_stripe_process_payment_error ($error, $order) – Called when
an error occurs during the process payment event.
add_action( 'wc_gateway_stripe_process_payment_error', 'test_this' );
What am I missing? Is there another filter or hook that I should be using?
As per documentation https://docs.woocommerce.com/document/stripe/ this hook take 2 params $error, $order so you have to tell it to WordPress:
add_action( 'wc_gateway_stripe_process_payment_error', 'test_this', 10, 2 );
function test_this($error, $order) {
// something
}
It's working fine on my side
The only way I could figure out how to do this is by watching for dod inserts on the dom. This is the code I used below.
Note: You should probably use mutated events these days but for some reason, I couldn't figure it out.
$(document).on('DOMNodeInserted', function(e) {
if ( $(e.target).hasClass('woocommerce-error') ) {
console.log('stripe input error');
}
});
I have a product what have attribute limited-edition-counter. When someone will buy this product I need to increment this attribute.
I tried to use add_action( 'woocommerce_order_status_completed', _my_function, 10, 1);
but it isn't called after order. It's only one trigger what I found to call after each order.
I use own plugin to extends WP.
Any hints how can I solve this problem?
Thanks in advance.
you can use woocommerce_thankyou hook so it will call everytime when someone order from the store.
add_action( 'woocommerce_thankyou', 'your_function' );
function your_function()
{
//access `limited-edition-counter` attribute here and increment it here
}
I understand how actions work, something like this:
do_action() invokes all functions hooked to the action hook
add_action() hook the functions which we want to be invoked in some moment to an action hook but it won't invoked till do_action work
When i read in wordpress code for example add_submenu_page function there is something like this:
$hookname = get_plugin_page_hookname( $menu_slug, $parent_slug);
if (!empty ( $function ) && !empty ( $hookname ))
add_action( $hookname, $function );
My question is: what is the use of $hookname in add_action() and how to invoke the function ?
If you define a function:
function my_function() {
// Code here
}
And then make it an action using:
add_action( 'my_hook_name', 'my_function' );
It will be called whenever there is a call like:
do_action( 'my_hook_name' );
But the 'do_action()' is different to calling the function directly because it will also call any other functions that have been added to that hook. If you look at the docs for WordPress hooks you will see that there is a way to control the order of the actions when the 'do_action()' is called.
I've got two functions:
add_action( 'woocommerce_order_status_completed' , 'after_order_complete' , 10);
function after_order_complete( $order_id )
{
error_log("woocommerce_order_status_completed", 0);
}
add_action( 'wp_login', 'after_login', 10, 2);
function after_login( $user_login, $user ) {
error_log("wp_login", 0);
}
that I can't seem to get called, tried in a plugin and functions.php but they never fire and no errors are logged.
How is it I debug this to find out why they fail or does anyone know how to get these to work?
In the same code I have another add_action but this time using user_register and that works as expected from plugin or functions.php
Edit:
I have the wp_login figured out, action does get called but only when first visiting the back end, site is front end only for users so used membership system hook instead.
I'm new to WordPress plugin development. I have a doubt about below 3
filter hooks.
content_edit_pre
content_filtered_edit_pre
excerpt_edit_pre
Please tell me the what the difference between these hooks.
content_edit_pre filter hook
The content_edit_pre filter hook is used to hook into the content of a post just before it is loaded to be edited. For example, if you included the following at the end of your functions file:
function test_of_content_edit_pre( $content, $post_id ) {
return "Insert this before the content about to be edited ".$content;
}
add_filter( 'content_edit_pre', 'test_of_content_edit_pre', 10, 2 );
Then open a post to edit it, you would see that the text has been inserted before the post:
excerpt_edit_pre filter hook
The excerpt_edit_pre filter hook is very similar to content_edit_pre, except it is used to hook into excerpts (instead of posts) just before they are loaded to be edited. For example:
function test_of_excerpt_edit_pre( $content, $post_id ) {
return "Add this to excerpt".$content;
}
add_filter( 'excerpt_edit_pre', 'test_of_excerpt_edit_pre', 11, 2 );
Would result in this being shown in the excerpt:
content_filtered_edit_pre filter hook
This one I am not sure about. I tested it out and it didn't seem to do anything. I will update my answer if I can find more information on this.