Skip Navigation

[Résolu] How to set up a "Contact Listing Author" for listing pages on classifieds site

This support ticket is created Il y a 8 années et 4 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Ce sujet contient 2 réponses, a 3 voix.

Dernière mise à jour par Itamar Il y a 8 années et 1 mois.

Assisté par: Eduard.

Auteur
Publications
#357999

Jay

I have a classifieds listings site. Users can post listings for free. But they have to register with an email/username and password in order to create ads. And when they are logged in, obviously manage their listings via their account page.

Users that just want to view listings do not need to log in. However, when any user is on a single post listing page (created by a registered author), they need to be able to contact the author of the ad.

I would like to include a small form on single listing pages that has "subject", "message", and "submit" fields.

The authors email should not be displayed. When the user submits the form, the message should go to the author of the post's email that he registered with.

I saw in the Toolset classifieds demo there was a messaging system but that was overkill for my needs and I would like all back and forth messaging regarding listings to happen off site - other than the initial "user > author" message.

Is this possible to do? Thanks for any info!

#358101

Hi,

*** Please make a FULL BACKUP of your database and website.***

1.
I would suggest to create a contact form post type and CRED form like described in here:
lien caché

2.
Then add new CRED form to your listings view.

3.
And finally add the following code to your themes. functions.php
This will change the recipient to send notification only to listing author.

/**
 * Filter CRED notification recipients.
 * This code will send notification to author of page/post on which the CRED form is placed.
 *
 * @param array   $recipients   Array of recipients who will receive notification.
 * @param string  $notification Notification message.
 * @param integer $form_id      CRED form ID
 *
 * @return array                 Array with update recipients.
 */
function update_cred_notification_recipients( $recipients, $notification, $form_id ) {
	// Do this only for specific form
	if( 271 === $form_id ) {
		// Check if CRED container ID is set to get the page/post ID
		if( isset( $_POST['_cred_cred_prefix_cred_container_id'] )
		    && is_numeric( $_POST['_cred_cred_prefix_cred_container_id'] )
		) {
			// Get current page/post object.
			$post_id = absint( $_POST['_cred_cred_prefix_cred_container_id'] );
			$post = get_post( $post_id );
			if( is_a( $post, 'WP_Post' ) ) {
				// Get page/post author email.
				$email = sanitize_email( get_the_author_meta( 'user_email' , $post->post_author ) );
				// Change recipient array to send notification to page/post author only.
				$recipients = array( array( 'address' => $email, 'to' => false, 'name' => false, 'lastname' => false ) );
			}
		}
	}
	return $recipients;
}
add_filter( 'cred_notification_recipients', 'update_cred_notification_recipients', 10, 3 );

Hope this will resolve your issue.

Please let me know if you will have any issue.

Thanks

#381720

Itamar
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Jerusalem (GMT+03:00)

Another user has provided some more details on his specific solution here:
https://toolset.com/forums/topic/please-could-you-add-this-to-reply-357999/

Ce ticket est maintenant fermé. Si vous êtes un client de Toolset et que vous avez besoin d'aide, veuillez ouvrir un nouveau ticket d'assistance