Displaying the seller's attribute if they don't pay for their membership

Hello,

I would like to ask for help with creating a code that I will insert into a code snippet for this function or situation.
I have a paid seller who renews his membership every month. In the attributes I have a condition that certain seller attributes (email, phone, facebook, instagram) will only be displayed if he pays the membership fee every month.
I need help with the situation if the membership fee is not paid. The seller’s profile will remain displayed, but the contact details should not be displayed (this situation motivates him to pay the membership fee regularly, every 30 days). If visitors do not see his contacts, they cannot call and write to him and arrange the performance of the service.
I found out that the plugin does not have a function that would prohibit the display of the contact attribute (which I have limited). If the seller does not pay the membership fee, the phone, email … are still displayed.
Please can you help me with this by editing the code that would prohibit it from being displayed:

well thank you

Alica

Thanks for your message — our team will reply shortly.

In the meantime, you can also get instant help from our AI Assistant, familiar with all the docs and solutions we’ve shared over the years.

Hi,

Apologies for the delayed response, and thank you for your patience.

Please use the following code snippet:

add_filter(
	'hivepress/v1/models/vendor/fields',
	function( $fields, $object ) {
		if ( is_admin() || hivepress()->helper->is_rest() ) {
			return $fields;
		}

		$user_id = absint( get_post_field( 'post_author', $object->get_id() ) );

		if ( ! $user_id ) {
			return $fields;
		}

		$membership = \HivePress\Models\Membership::query()->filter(
			[
				'status' => 'publish',
				'user'   => $user_id,
			]
		)->get_first();

		// add comma-separated field names here
		$hidden_fields = [ 'telefon', 'any_custom_field' ];

		if ( $membership ) {
			$hidden_fields = array_diff( $hidden_fields, (array) $membership->get_vendor_edit_attributes() );
		}

		if ( ! $hidden_fields ) {
			return $fields;
		}

		foreach ( $hidden_fields as $field_name ) {
			if(isset($fields[ $field_name ])) {
				$fields[ $field_name ]['display_template'] = '';
			}
		}

		return $fields;
	}, 1000, 2
);

At the moment, when there is no active Membership plan or the plan has expired, the phone field will be replaced with an empty space:

$fields[ $field_name ]['display_template'] = '';

If needed, you can replace the empty value with a placeholder such as “Hidden” or something similar to indicate that the field exists but is not available, or keep it empty as in the original snippet.

You can also add more fields to the snippet if needed. Simply replace any_custom_field with the exact field name of the attribute you want to hide when the vendor no longer has an active plan.

Hope this helps!