Inicio › Toolset Professional Support › [Resuelto] Compare message date with WC Subscription End Date or Subscr. Status conditional
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | 9:00 – 13:00 | - | - | 9:00 – 13:00 |
14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - | - | 14:00 – 18:00 |
Supporter timezone: Africa/Casablanca (GMT+01:00)
Etiquetado: Content Templates, Views, Views plugin
Documentación relacionada:
Este tema contiene 5 respuestas, tiene 2 mensajes.
Última actualización por Jamal hace 4 años, 2 meses.
Asistido por: Jamal.
Dear Support
We have used Toolset to create our messaging system and now we would like to make a conditional statement to choose where to hyperlink the user to based on some conditions.
I have implemented some of it but am running into the point where it looks like I might need some custom code.
What I've managed so far:
1) User is role native_nanny or subscribed_family - link sends them to chatbox
2) User is role family (ie, never had a WooCommerce Subscription) - link sends them to shop where they can buy a subscription
However I am requesting help with:
3a) User is role lapsed_family (ie previously had at least one WooCommerce Subscription, but it has expired or was cancelled)
AND (new received message post date > Subsription end date) - send them to the shop page to purchase a subscription
3b) User is role lapsed_family (ie previously had at least one WooCommerce Subscription, but it has expired or was cancelled)
AND (new received message post date <= Subsription end date) - allow them to open the chatbox for that message thread
In plain English, the requirement would be that the role lapsed_family should still be able to open and see Messages which they had received while they were subscribed, but new messages which were received after the WC Subscription expiry date, should not be openable, and should send them to the shop page where they can subscribe again.
All 4 roles are already functioning well, I need advice/help getting the connection with WooCommerce Subscription End Date or perhaps Subsciption Active Status (wcs_user_has_subscription) to work in a conditional statement.
Thanks and regards
Simon
Hello Simon and thank you for contacting the Toolset support.
To better assist you with this issue, I would like you to provide some test scenarios that will explain what to do and what to expect, for example:
- Login with user xxx on page xxx.
- Go to page xxx.
- I expect to see xxx.
- Instead, I get xxx.
Please provide the test scenarios for all cases. Provide also details of where to change "subscription end date" so we can do it manually if it already passed and test with it.
Your next reply will be private to let you share credentials safely. I'll need FTP access to add the "Adminer" script for database browsing. A staging site would be preferable.
Hi Jamal
I was doing some more digging in the WooCommerce Subsctiptions plugin developer notes and I think what we may need to use some form of
WooCommerce Subscriber/User Filters (DOC: https://docs.woocommerce.com/document/subscriptions/develop/filter-reference/)
Filter: 'wcs_user_has_subscription'
to check if the current user ($user_id)
is subscribed to a certain product ($product_id)
(In our case these product IDs would be one of the 3 product variations of the Subsciption with ID 2592 which correspond to 1 month, 3 month or 6 month packages)
ID 2593 for 1 month
ID 2594 for 3 months
ID 2595 for 6 months
and the status of which ($status) is one of the following ("cancelled", "expired")
So the conditional test we'd need to achieve in the Toolset view "my-messages-received" would go something like this, in English:
IF
the role of the current user is equal to "lapsed_family"
AND the current user is subscribed to any of the Product IDs variations listed above from the Subscription Package with ID 2592
AND the status of said subscription is in ("cancelled", "expired")
AND the message post date is newer than max(Subscription Product End Date) (still struggling to find out how WC is calculating this!?)
THEN
link
Hello Simon,
Actually, I don't have advanced experience with the subscription plugin. I have used it a couple of times, but I did not produce a custom code that uses its data.
I believe that the best team to help is the WooCommerce Subscription support team. Please reach to them and ask how to get a user's subscription end date.
I am sorry, I can't help further.
HI Jamal
I found in the documentation how to get the subscription end date:
Step 2.2.3: Subscription Length
To get the end date or time for a subscription, it’s possible to call:
$subscription->get_time( 'end' );
Does this help?
Kind regards
Simon
Well, you still need to get the $subscription object.
According to this StackExchange thread, you can use wcs_get_users_subscriptions function to get a user's subscriptions.
https://wordpress.stackexchange.com/a/326656
According to WooCommerce code reference, there is a public method to get the connected user's subscriptions.
enlace oculto
Honestly, it is a 3rd party plugin, and the WooCommerce Subscriptions' support team is the best placed to answer this question about a subscription end time.