• I’m trying to identify the correct hook that will fire after a successful payment is processed – do you know what hook is the best? I’ve tried the
    following but have had no success….thinking they are not correct.

    I’ve tried:
    – membership_add_subscription
    – membership_payment_processed

    Do you know which hook I should use? Are the hooks documented anywhere? This is the final piece of my integration – hopefully you are able to help out!

    https://wordpress.org/plugins/membership/

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Bojan Radonic – WPMU DEV Support

    (@wpmudev-support4)

    Hey there schlackl,

    How are you doing today?

    Membership 2 has developer documentation that should help you find your answer for this. You can find it in your admin in Membership 2 -> Help -> API Docs.

    Hope this helps 🙂

    Cheers,
    Bojan

    Thread Starter schlackl

    (@schlackl)

    Hi there – yes, I’ve looked at the API Docs and they have indeed been helpful when it comes to accessing members and their subscriptions, however the docs make little or no mention of hooks.

    What I’ve tried I’ve found by hunting through the code looking at do_action() calls.

    The only hook I see mentioned in the docs is ‘ms_init’ and ‘ms_active’
    Is there somewhere else that the hooks are documented?

    My issue is that I need to ensure that a purchased membership always expires on the following Monday regardless of what day of the week it is purchased. So it’s a finite membership but the length is variable based on the purchase day of week.

    I want to simply update the expiry date of the membership after the payment has been successfully processed. There must be a hook I can implement to initiate my update process….

    Any ideas?

    Plugin Author Bojan Radonic – WPMU DEV Support

    (@wpmudev-support4)

    Hey again schlackl,

    Unfortunately API docs is the only developer documentation that we have. To check for incoming payments you can use the following hook:

    do_action( 'ms_invoice_paid', $invoice, $subscription );

    Then to set that specific date you’d need to do something like this:

    $subscription->expire_date = ...; $subscription->save();

    Hope this helps 🙂

    Cheers,
    Bojan

    Thread Starter schlackl

    (@schlackl)

    Hi Bojan,

    Yes, I think that should work however I’m having a separate issue now – I’m trying to have the correct expiry date show on the “cart” screen after you add a membership and are ready to pay.

    I am using the hook ‘ms_view_frontend_payment_form_start’ and am setting the $subscription->expire_date and then calling $subscription->save()

    That doesn’t appear to be working – it still displays the incorrect expiry date on the screen “You will pay USD 0.99 for access until March 7, 2016 4:00 pm”

    It should be “You will pay USD 0.99 for access until February 29, 2016 4:00 pm”

    Here’s my function and add_action call code….do you see any issues with that? I need it to reset the expiry date when the membership is added to the cart and then of course be sure that date holds after payment is received.

    function setPreviewMembershipExpiryDate($membership, $objPurchase){
       //all preview membership should expire on a Monday
       //if it's a weekly membership then
       //      set it to expire "next Monday" if today is NOT Monday
       //      otherwise do nothing as it will expire in 7 days by default
       //if it's an annual membership then
       //      set it to expire the "last Monday" from current expiry if current expiry is NOT Monday
       //      otherwise do nothing as it already expires on a Monday
       $subscription = $objPurchase->data['ms_relationship'];
       $membership = $objPurchase->data['membership'];
       $cur_expiry_date = $subscription->calc_expire_date($subscription->start_date);
       if($membership->period['period_unit'] == 7){
          //weekly membership
          $dow = date ('l');
          if($dow != "Monday"){
               $cur_expiry_date = strtotime("next Monday", time());
               $new_start_date = strtotime("last Monday", time());
          }
    
          $cur_expiry_date = date('Y-m-d', $cur_expiry_date);
          $new_start_date = date('Y-m-d', $new_start_date);
          $subscription->start_date = $new_start_date;
          $subscription->expire_date = $cur_expiry_date;
          $subscription->save();
       }
    }
    
    add_action( 'ms_view_frontend_payment_form_start', 'setPreviewMembershipExpiryDate', 10, 2 );
    Plugin Author Bojan Radonic – WPMU DEV Support

    (@wpmudev-support4)

    Hey again schlackl,

    As much as I’d like to help here this is above my knowledge scope and for creating custom solutions like this one you’d probably want to hire a developer to assist you further.

    Best regards,
    Bojan

    Thread Starter schlackl

    (@schlackl)

    Seriously? I AM a developer! I thought you were too…well guess I’ll have to go through your code to figure out how it works – just figured you would know seeing as you are the plugin developer….

    Plugin Author Bojan Radonic – WPMU DEV Support

    (@wpmudev-support4)

    Hey again,

    I’m tech support staff at WPMU DEV, I know a thing or two about coding but I can’t really say that I’m a developer.

    Hope you’re going to manage to find a solution for you problem 🙂

    cheers,
    Bojan

    Thread Starter schlackl

    (@schlackl)

    I see….

    OK – one more question – can I customize the text that displays in the plugin screens? Some phrases I’d like to change such as “Join Membership” and “Please check the details of the membership below…”

    Is it possible to customize those phrases?

    Plugin Author Bojan Radonic – WPMU DEV Support

    (@wpmudev-support4)

    Hey again schlackl,

    Definitely, plugin is translation ready so you can change any text in the plugin. You’ll find more information on how to use translation files here.

    Hope this helps 🙂

    Cheers,
    Bojan

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘What is the correct hook that fires after a payment is processed?’ is closed to new replies.