• Resolved thatgirlslays

    (@thatgirlslays)


    Hello,

    I have a product that basically lets people create a customized widget they can use on their website using an embed code. They must purchase a yearly subscription in order to access the widget creator and also for the embed code of the widget to work properly. I just started using YITH Woocommerce Subscription. I created a new product called “My Widgets” and set it as a subscription type with the period being 12 months. On the “My Widgets page”, I would like to add a PHP/MySQL conditional check to see if the current user has an active subscription to the “My Widgets” product. The “My Widgets” page is NOT the product page, this is a completely different page I have created as a landing page where they can see all the widgets they have created and either create a new one, edit an existing one or delete one. From this page, I would like to display a notice to let them know if their subscription to the “My Widgets” product has expired and if so, give them a link to renew their subscription. My issue right now is that I’m not sure where in the database the subscriptions are stored so I am unable to do the conditional check to determine whether or not their subscription to the “My Widgets” product is active or expired. I am using the free version of this plugin.

    EDIT: I manually added a test order for myself but I see it did not automatically add a subscription to the product like I thought it would. I went to the Subscriptions section of my admin portal and no subscriptions were listed. There also doesn’t seem to be a way to manually add a subscription in the back end like you can for products/orders/posts/etc. So another question: how do I manually add a subscription for a user?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter thatgirlslays

    (@thatgirlslays)

    Ok, I created a subscription for myself on the front end by adding the product to my cart and checking out using check payment method. I then went to the admin portal and manually completed/approved the order. So now my user account has an active subscription.

    However, I am not sure how to query whether or not the logged in user has an active subscription for a specific product and then return either true or false.

    When a new subscription is made, several post meta rows are created. Here are some examples:

    post_id: 468
    meta_key: _product_id
    meta_value: 432
    
    post_id: 468
    meta_key: _status
    meta_value: active
    
    post_id: 468
    meta_key: _user_id
    meta_value: 1

    In this examples, user #1 (my admin account) has an “active” subscription to the product with the ID “432”. The subscription is ID “468”. I need a way to query and determine whether all 3 of these conditions are true for the given user and the specific product.

    • This reply was modified 7 years, 5 months ago by thatgirlslays.
    Thread Starter thatgirlslays

    (@thatgirlslays)

    Nevermind I found a query that works thanks to StackOverflow.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to Determine if Subscription is Expired Using PHP/MySQL’ is closed to new replies.