• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Validating a user has an active subscription in woocommerce

#1
Hi Everyone,

My users come in through a subscription in woocommerce on a wordpress site. Once they have an active subscription I add them manually to XenForo. (Not perfect... but that automation part can come later).

My custom wordpress plugin updates the their user records (wp_usermeta) with a active subscription flag based on the woocommerce subscription status.

What I need to do is make an api call to my script on the wordpress site (could be direct sql as both are on the same server) to check if the user has an active subscription (or not) every time they login.

I'm a php pro with 15 years of experience, so I'll be comfortable coding what's needed.

I'm just 3 days old in XenForo, so please could someone point me in the right direction :) Where do I start looking ?

Thanks & Regards

Blake

P.S Apologies if this is posted in the wrong place.
 

Jeff Berry

Well-known member
#2
Assuming you use the same user email for both their XF account and their wordpress account, it should be something similar to this. Note that this is untested.

PHP:
SELECT usermeta.meta_value AS subscriptionValue 
FROM wp_users AS users
INNER JOIN wp_usermeta AS usermeta
    ON (usermeta.user_id = users.user_id)
WHERE usermeta.meta_key = 'subscriptionFlag'
    AND user.user_email = 'usersXfEmail'
You need to change the values in red to match your application. The first one would be the name of your meta key that flags their subscription status, the second being the user's email address (this will obviously be a variable).
 
#3
Thanks @Jeff Berry , The wordpress side I have down to a T. I did the test add on through the tutorials, and starting to get some knowledge about how I should be coding this.

I see there are upgrades in XenForo, so I might decide to use those rather than rely on WordPress.

Still investigating.

Cheers
 

Jeff Berry

Well-known member
#4
Well, welcome to XenForo :)

Let me tell you, I work professionally for a web development company and (unfortunately) we do a LOT of wordpress sites. I also develop for XenForo as just a personal endeavor. XenForo is lightyears ahead of Wordpress, I highly suggest you use it to it's fullest potential. You'll never look back on WP once you get the hang of it. I hate working on Wordpress at work now because I'm so spoiled with the privilege to work on XF.

Either way, don't give up on XF. It takes a while to get the hang of it and figure out how everything works, but once you do it's real simple :)