Help with Friendbuy and Membership 2 Pro

I'm trying to integrate Friendbuy, a referral program, into my website, which uses membership2 pro. The conversion tracker code requires an order id, amount, coupon code, and user email. So I'm wondering how membership2 can return those details. This is the conversion tracker code:

<script>
window['friendbuy'] = window['friendbuy'] || [];
window['friendbuy'].push(['track', 'order',
{
id: '', //INPUT ORDER ID
amount: '0.00', //INPUT ORDER AMOUNT
coupon_code: '', //OPTIONAL, coupon code if used for order
new_customer: '', //OPTIONAL, true if this is the customer's first purchase
email: '' //INPUT EMAIL
}
]);
</script>

For further details, I would put this script in the head element of the order confirmation (thank you) page. My coding skills are very rusty. Can you guys help, please?

  • Kasia Swiderska
    • Support nomad

    Hello Logan,

    We had some changes in Membership 2 Pro code recently that makes this task little more tricky - I have send message to one of the lead developers of plugin to provide correct hook for that action.
    As I understand that would need only work for initial payment of the subscription?

    At the moment developer is not online, so when they provide more info I will update thread with it.

    kind regards,
    Kasia

  • Kasia Swiderska
    • Support nomad

    Hello Logan,

    Our developer provided this sample code you can use:

    <?php
    $member = MS_Model_Member::get_current_member(); //Current member
    $member->email; //email
    $sub = null;
    foreach ( $member->subscriptions as $subscription ) {
        if ( $subscription ) {
            if ( $subscription->is_system() ) { continue; }
            $membership = $subscription->get_membership();
            if ( $membership->is_valid() ) {
                $sub = $subscription;
            }
        }
    }
    if ( $sub ) {
        $invoice = $sub->get_current_invoice( false );
    }
    ?>
    
    <script>
    window['friendbuy'] = window['friendbuy'] || [];
    window['friendbuy'].push(['track', 'order',
    {
    id: '<?php echo $invoice->get_invoice_number(); ?>', //INPUT ORDER ID
    amount: '<?php echo $invoice->total; ?>', //INPUT ORDER AMOUNT
    coupon_code: '', //OPTIONAL, coupon code if used for order
    new_customer: '', //OPTIONAL, true if this is the customer's first purchase
    email: '<?php echo $member->email; ?>' //INPUT EMAIL
    }
    ]);
    </script>

    You can use this code on Thank You page by putting it in the custom template for this page. You will find instructions how to have this page in Membership 2 -> Help -> Customize Membership 2

    Let us know if you have more questions.

    kind regards,
    Kasia

  • Kasia Swiderska
    • Support nomad

    Hello Logan,

    To create custom templates follow Codex of WordPress https://developer.wordpress.org/themes/basics/template-files/ - by default Membership is using page.php template of your theme, so to customize it you need to create your own template.

    Please also note that m2-protected-content-100.php is for Protected Content Page of Membership with ID 100 and not for the Thank you Page (that would be m2-registration-complete-100.php for subscribing to membership with ID 100).

    kind regards,
    Kasia

  • Logan Stark
    • WPMU DEV Initiate

    Hi Kaisia Thank you for the information.
    So to be clear I should just add the script above to the already existing information in the thank you and make that a new template.
    I should NOT create a new thank you page with the script above because it would be missing some information correct?

    Again thanks in advance for assisting me with this.

  • Logan Stark
    • WPMU DEV Initiate

    follow up question
    I thought maybe I am not asking this properly.
    Is there a way for me to edit the m2-registration-complete-100.php with the script above?
    If there is not and i have to create a template from the page.php template how would i associate it the newly created template with the m2 registration compete?

    Again thank you in advance

  • Kasia Swiderska
    • Support nomad

    Hello Logan,

    Membership 2 Pro is using default page.php template from your theme, so there is no specific template for Thank you page for editing.
    You need to create new file in your theme and name it m2-registration-complete-100.php (this is name with example ID 100 of membership, so you need to use real ID of your membership - you can find it on Memberships list in Shortcode column).
    After that you have to copy content of the page.php file into your new m2-registration-complete-100.php and then apply your changes to that new file.
    Here is more information on theme templates files https://developer.wordpress.org/themes/basics/template-files/

    kind regards,
    Kasia

  • Logan Stark
    • WPMU DEV Initiate

    Hi WPMU Team,

    Thanks for the solution provided above. I would like to ask if you could please answer a few questions.

    First, after creating the m2-registration-complete-100.php , where do I locate the file?
    Second, where can I find the real ID of my membership? (This question is so I can rename m2-registration-complete-"my id goes here. )

    Thanks for your time.

    Walter

  • Predrag Dubajic
    • Support

    Hi Walter,

    First, after creating the m2-registration-complete-100.php , where do I locate the file?

    How exactly did you create this file?
    It should be created in your child theme, you can copy page.php from your parent theme, place it in the child theme and then rename it to m2-registration-complete-100.php.
    You can then edit that file to adjust the registration template for that membership.

    Second, where can I find the real ID of my membership? (This question is so I can rename m2-registration-complete-"my id goes here. )

    You can go to Membership 2 > Memberships and from there you can either hover on the membership name, that will show the ID as part of the URL, or hover on Show in shortcodes column and ID will be shown in the shortcodes.

    Best regards,
    Predrag

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.