• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Payments Plugin for Stripe

Stripe payment plugins for your WordPress site

  • Home
  • Documentation
  • Addons
  • Login
    • Sign In
    • Edit Profile
    • Terms & Conditions
    • My Downloads
    • License Key
  • Support
    • Support Forum
    • Forum Search
    • Forum Login
    • Forum Registration
    • Email Support for Customers
  • Contact Us
  • Show Search
Hide Search
You are here: Home / Topics / I need to hook into the cancel subscription function

[Resolved] I need to hook into the cancel subscription function

· ·

Home › Forums › Stripe Payments Plugin › I need to hook into the cancel subscription function

Tagged: cancellation hook

  • This topic has 8 replies, 4 voices, and was last updated 8 months, 1 week ago by benbois.
Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • August 31, 2021 at 9:37 am #4234
    davidkochg
    Participant

    Hi S plugin

    Is there a way to add my own function when a subscription is chancelled?

    BR,
    Jesper

    August 31, 2021 at 10:54 am #4235
    alexanderfoxc
    Participant

    Hi Jesper.

    There are two hooks related to subscription deletion – asp_subscription_ended and asp_subscription_canceled. The latter is what you need. Here’s how you can hook to it:

    
    add_action ('asp_subscription_canceled', 'asp_subscription_canceled_handler', 10, 2);
    
    function asp_subscription_canceled_handler ($sub_id, $event_data) {
       ASP_Debug_Logger::log(json_encode($event_data));
    }
    

    $sub_id is Stripe’s subscription ID
    $event_data is event data received from Stripe’s hook.

    This code dumps event data into plugin’s debug log (if it’s enabled). This way you would be able to see what kind of data is available.

    To trigger the event, just create a subscription in test mode and then cancel it using cancel URL.

    July 12, 2022 at 9:00 am #4617
    benbois
    Participant

    Hi,

    I inserted your sample code in the functions.php file (child theme) but it is not fired after a cancellation, either by using a cancellation link (https://domain.com/?asp_sub_action=cancel&sub_token=XXXXX) or by clicking on the Cancel Subscription button (admin).
    Right now, only tested with Stripe Test Mode.

    Any idea?

    July 12, 2022 at 9:34 am #4618
    benbois
    Participant

    Well, apparently the usage of this hook has been limited to WP-Members Membership Plugin.
    Can you confirm?!

    July 13, 2022 at 3:57 am #4621
    Admin
    Keymaster

    We are not familiar with that particular plugin you mentioned but yes there are some plugins out there which can create a conflict. So the best option is to do the following test:

    Test for Plugin and Theme Conflict Before Posting an Issue or a Bug

    July 14, 2022 at 6:39 am #4623
    benbois
    Participant

    Strange, after disable all plugins & gone back to a standard theme (Sketch), the hook still refuse to fired!
    The hook works when added inside your code (after the hook for eMember plugin) but not outside of the plugin, in functions.php file for example?!

    July 15, 2022 at 4:41 am #4628
    Admin
    Keymaster

    This particular hook is triggered by a Stripe hook. It runs early on the loading process so this code needs to be put into a place that is visible much earlier. If you are putting the code into a file that is loading AFTER the hook is being triggered, then you will see the behavior that you are seeing. Not all hooks are triggered at the same time. Different hooks have different conditions. You may need to get help from a WordPress coder for this.

    You should probably make a small custom plugin and put this custom code in that plugin so it is visible when that hook is triggered. It’s generally a good idea to put all your customization code into a separate plugin. Otherwise in the future if you switch your theme, you will lose all the customization.

    July 15, 2022 at 6:30 am #4629
    benbois
    Participant

    Thanks for your reply.
    I’ll try out in a separate plugin.

    July 15, 2022 at 8:07 am #4630
    benbois
    Participant

    Thanks, it works perfectly in a plugin.
    That was the key, as mentioned above, to trigger earlier with this hook!

    Problem solved!

  • Author
    Posts
Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.
Log In

Primary Sidebar

Featured Addons and Extensions

  • Subscription Payments Addon
  • Additional Custom Fields
  • Secure Downloads Addon
  • Apple Pay, Google Pay, Afterpay

Addon Bundle

Stripe Payments Addon Bundle

Support Links

  • Support Forum
  • Support Contact

Search

Copyright © 2023 | Stripe Plugins | A member of the Tips and Tricks HQ family.