• Hi,
    why the “Send Data On User Update” is triggered when a customer complete an order?
    I want to trigger this webhoock just when a customer update his profile: how can I do it?

    Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Ironikus

    (@ironikus)

    Hey @vforte – thank you very much for reaching out, as well as for using our plugin.
    The trigger fires since Woocommerce is updating the customer as well within that call, which is technically correct to fire.
    If you want to fully control where to fire it or not, you would require some custom code.

    Down below, I created an example for you that allows you to only fire the trigger when a user visits his profile page within the backend. This should give you a better understanding on how you can make it.

    Please note: Once you added the code, the trigger will only fire once you are on your profile.php page within your admin area.

    add_filter( 'wpwhpro/admin/webhooks/is_valid_trigger_response', 'limit_user_update_webhook_trigger', 10, 4 );
    function limit_user_update_webhook_trigger( $response, $webhook, $data, $args ){
    
        //Make sure we only check on the update_user webhook trigger
        if( is_array( $webhook ) && isset( $webhook['webhook_name'] ) && $webhook['webhook_name'] === 'update_user' ){
    
            //Load the current page definition
            global $pagenow;
    
            //Set the webhook trigger by default to false - this causes the trigger to not fire at all
            $response['is_valid'] = false;
    
            //Check if the user is on the profile page and only then allow the trigger to fire
            if( $pagenow == 'profile.php' ){
                $response['is_valid'] = false;
            }
    
        }
    
        return $response;
    }

    If you have any further questions, feel free to reach out again.

    Thread Starter vforte

    (@vforte)

    Hi @ironikus,
    is it needed the Pro version of WP Webhooks?

    Thank you very much for your time.

    • This reply was modified 4 years, 3 months ago by vforte.
    Plugin Contributor Ironikus

    (@ironikus)

    Hey @vforte – no, this also works with the free version. ??

    Thread Starter vforte

    (@vforte)

    Something is wrong then: the limit_user_update_webhook_trigger function is never called and also the trigger is never fired.

    Plugin Contributor Ironikus

    (@ironikus)

    @vforte – How did you make sure the function is not fired?
    If you include the function, there’s no other webhook fired for the update_user webhook trigger, except it is fired on the following page: https://YOURDOMAIN/wp-admin/user/profile.php

    Thread Starter vforte

    (@vforte)

    @ironikus I just trie to put some debug calls (such var_dump(…), echo, exit, etc…) at the beginning of the limit_user_update_webhook_trigger function and I realized in this way that it is never called.

    I put the snippet inside my functions.php
    Also (perhaps not relevant), my Profile page is at https://MYDOMAIN/wp-admin/profile.php

    Plugin Contributor Ironikus

    (@ironikus)

    @vforte – If the function is never fired, there was no webhook call for any trigger. This filter is located right before we create the WP_Http request to send out the data from your website.

    In that case, I can think of the following reasons:

    1. There was no webhook trigger that could have been fired
    2. Our trigger runs on the WordPress profile_update hook – this one wasn’t triggered then
    3. The function fired, but you haven’t realized that

    To explain a bit more about the last point: Exiting our outputting content is always a nice thing for debugging, but doesn’t always work properly. Since we precache the webhooks for each WordPress instance, we send them over shortly before PHP shuts down, which means that all the content is already loaded at that point. The better way to test it is to use error_log() and check if there was some input within your debug.log file.

    And apologies for the profile page URL – I assumed you use a multisite network.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Avoid to trigger “Send Data On User Update” webhook on new WooCommerce order’ is closed to new replies.