Skip Navigation

[Resolved] Creating a featured Advert

This support ticket is created 6 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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: Asia/Kolkata (GMT+05:30)

This topic contains 7 replies, has 2 voices.

Last updated by Minesh 6 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#919420

Tell us what you are trying to do?

Hi Toolset

I looking for a bit of advice on an element of my current project, so to date, we are using a combination of Toolset and Woocommerce + Subscriptions + Memberships.

We are using Toolset to create CPT, views, access and cred forms, it’s a fan site so the Woocommerce elements take care off subscriptions and memberships and Toolset for the CPT(s) Fans, Performers, and Agency all works great.

The fans can view the performers and agencies and the performers can create a profile, while an agency can create many, all with different access roles.

Now I’ve created another subscription called Featured which either an Agency or Performer can purchase (basically a Featured Advert at the top of the page ), what we would like to do is to create a view that can filter any Performer or Agency who has an active subscription, I’ve implemented an elegant function that Beda created for a u_count_post to restrict the number of posts that can be created so I kinda understand who it works, so you can help point me in the right direction. So maybe the 'wcs_user_has_subscription'

https://docs.woocommerce.com/document/subscriptions/develop/filter-reference/#

Any help would be very appreciated, or open to any other ideas.

Kind Regards

Nigel

Is there any documentation that you are following?
https://docs.woocommerce.com/document/subscriptions/develop/filter-reference/#
'wcs_user_has_subscription'

Is there a similar example that we can see?

What is the link to your site?

#919943

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

As I understand - you only want to list the users who has Featured subscription?

#920038

Yes that is correct

#920333

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please share problem URL where you want to display the view with results and access details.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#920394

Okay, the details have been sent to you, however, please let me clarify.

We are looking at creating a View that filters any 'Performer' or 'Agency' that has purchased a subscription 'Featured' and is 'Active'

This VIEW has not been created yet, we were looking at advice on how to best go about this.

WooCommerce Subscriptions has a filter called

wcs_user_has_subscription

which might help to filter this VEIW.

All other elements are currently working on the site

#920831

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - Thanks for sharing access details and your detailed explanation.

We are looking at creating a View that filters any 'Performer' or 'Agency' that has purchased a subscription 'Featured' and is 'Active'.

I checked the WooCommerce Subscription filter: wcs_user_has_subscription - It checks the user ID.

In order to have my doubt clear here as I see 'Performer' or 'Agency' setup as custom post type as well as roles as well.
=> So I would like to know here - you want to check currently logged in user or you want to filter the post type posts of 'Performer' or 'Agency' post types with "Featured" subscription.

OR

You want to display list of user's who have "Featured" product subscription.

#920929

Hi Minesh

Yes: We are looking at creating a View that filters any 'Performer' or 'Agency' that has purchased a subscription 'Featured' and is 'Active'.

Yes: "...you want to filter the post type posts of 'Performer' or 'Agency' post types with "Featured" subscription."

Yes imagine a directory that displays on the front page a VIEW(s) that lists (featured image, post link) of Performers and Agencies, however, a 'Performer or 'Agency' can purchase a 'Featured' subscription that would be displayed above the other 'Performers' this would be the VIEW that we wish to create.

So we have a VIEW that filters a 'Performer' or 'Agency' that has a 'Featured' Subscription that is Active and their details are displayed.

Heres some extra research I've done that may help, my thoughts are to add a function (similar to the one below) ?

hidden link

AND

/**
 * Check if a user has a subscription, optionally to a specific product and/or with a certain status.
 *
 * @param int $user_id (optional) The ID of a user in the store. If left empty, the current user's ID will be used.
 * @param int $product_id (optional) The ID of a product in the store. If left empty, the function will see if the user has any subscription.
 * @param mixed $status (optional) A valid subscription status string or array. If left empty, the function will see if the user has a subscription of any status.
 * @since 2.0
 *
 * @return bool
 */
function wcs_user_has_subscription( $user_id = 0, $product_id = '', $status = 'any' ) {
	$subscriptions = wcs_get_users_subscriptions( $user_id );
	$has_subscription = false;
	if ( empty( $product_id ) ) { // Any subscription
		if ( ! empty( $status ) && 'any' != $status ) { // We need to check for a specific status
			foreach ( $subscriptions as $subscription ) {
				if ( $subscription->has_status( $status ) ) {
					$has_subscription = true;
					break;
				}
			}
		} elseif ( ! empty( $subscriptions ) ) {
			$has_subscription = true;
		}
	} else {
		foreach ( $subscriptions as $subscription ) {
			if ( $subscription->has_product( $product_id ) && ( empty( $status ) || 'any' == $status || $subscription->has_status( $status ) ) ) {
				$has_subscription = true;
				break;
			}
		}
	}
	return apply_filters( 'wcs_user_has_subscription', $has_subscription, $user_id, $product_id, $status );
}
#921188

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Thanks for all details.

Well - the thing is that there are couple of situations I would like to know - when user will purchase a subscription - is there any chance that you will assign a new role something "featured-subscription"? If yes:

Then - with the VIEW - you want to display 'Performer' posts created by 'Performer' or 'Agency' - correct? and at that time the author of the 'performer' post will be the same user (either 'Performer' or 'Agency).

So, when you create a view that queries the performer - you can either use [wpv-conditional] shortcode to compare the current role assigned to post author - if that is "featured-subscription" - then display the post, otherwise no.

When "featured-subscription" expires - the user should be assigned a different role - that means only active subscriptions will have "featured-subscription" role assigned to user.

Will this help or you have different idea?