Skip Navigation

[Resolved] Contact Listing Owner Form

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 3 replies, has 2 voices.

Last updated by Minesh 1 year, 5 months ago.

Assisted by: Minesh.

Author
Posts
#2624871

I am currently working on a feature for my website that allows guests to contact listing owners for more information. I have two types of users on my site: Designers and Partners, both of whom have listings.

To facilitate this, I have created a Custom Post Type (CPT) called 'Contact' and established a one-to-many relationship with the 'Designers' CPT. However, I am encountering difficulties in setting up the form to send the message to the correct listing owner.

When I create a form for the 'Contact' CPT and set the message to go to the listing owner, it seems to be directed to the 'Contact' list owner instead. To address this, I attempted to use a connection form, but I am unable to find an option to notify the actual listing owner.

Could you please provide detailed instructions on how to create a 'Contact Listing Owner' form that sends the message to the correct listing owner? I would like to implement this feature for both 'Designers' and 'Partners' listings.

Thank you for your assistance. I look forward to your guidance.

#2624891

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Can you please confirm where you added the form? Did you added the form on the single post of your listing post type so every single post of listing post type will have the contact form?

In addition to that - Could you please send me debug information that will help us to investigate your issue.
=> https://toolset.com/faq/provide-debug-information-faster-support/

#2625011

So I am not sure what from to add to where? That is issue. Initially I created a regular Post Form for a CPT called "Contact" and made it so that the the listing owner of that CPT (Contact) would get the notification when someone filled out the form, then i put it on the Designer CPT Listing Template (the single page, so that every page had the form, and updated the access so that guests could access it). But then I realized that since the form that I created was built on its own CPT "Contact" and not "Designers" I figured that it would not work when someone filled out the form since the form owner in that case was the form owner of the "contact" CPT not the Designer. I didn't even test it out because i figured it would not work that way.

So then I tried creating a One to Many connection between the Designers and The Contact with the One being the Designer and the Contact being the many. At that point I wasn't sure how to proceed.... so i tried creating a new relationship form between the Desinger and the Contacts. But at that point i was lost as i cold not find any notification settings to notify the listing owner like there were on the regular post forms.

So my question is, what is the proper way to set up a contact listing owner form? So I can do it. It seems like this is a major feature and there should be a tutorial on it. right?

#2625315

Minesh
Supporter

Languages: English (English )

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

The proper way is you can create one to many post relationship between the post type Designer (one) and Contact (many).

Then you also followed the correct step that you will have to add the contact form on the single post content template of the post type Designer. Make sure you added and configured the email notification for your form on form submit.

Then what we will do is, you can use the Toolset form's hook "cred_notification_recipients" to send email notification to parent post author. In your case, send notification to designer post's author.

You can add the following code to "Custom Code" section offered by Toolset:
- https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#benefits-of-adding-custom-code-using-toolset

add_filter('cred_notification_recipients', 'func_send_notification_to_parent_post_author', 10, 4);
function func_send_notification_to_parent_post_author($recipients, $notification, $form_id, $post_id){
    if ( $form_id == 99999){

        $relationship_slug = 'your-one-to-many-relationship-slug';
        $parent_post_id = toolset_get_related_post( $post_id, $relationship_slug );

        $author_id = get_post_field( 'post_author', $parent_post_id );
        $author_email = get_the_author_meta( 'user_email', $author_id );
         
        $recipients[] = array(
            'to'=>'to',
            'address'=>$author_email,
            'name'=>'',
            'lastname'=>''
        );
    }
    return $recipients;
}

Where:
- Replace 99999 with your original form ID
- Replace 'your-one-to-many-relationship-slug' with your original one-to-many post relationship slug

More info:
- https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post
- https://toolset.com/documentation/programmer-reference/cred-api/#cred_notification_recipients