Welcome email message after add listing

I send standard email to every new joiner to welcome them to the website (this way they will also get a feeling how the message-ing works). same as google is doing when getting a gmail account via this code: Showing empty account pages and sending welcome email - #7 by yevhen

but i need send email after add first listing too, but with change of code on this it is not work. Pls help what i do bad?

add_action(
    'hivepress/v1/models/listing/save',
    function ($listing_id, $values) {

pls help me

Hi,

There is no such hook, so it doesn’t work. Please read this documentation: Home | HivePress Hook Reference

We recommend using the hivepress/v1/models/listing/update_status hook, for example, to catch status changes and then count the number of listings the user has, and if it’s the first one, send an email.

​I hope this is helpful to you.

Hello @andrii
am tryed this code but with 403 status error:

add_action('hivepress/v1/models/listing/update_status', function($listing_id, $status) {
    $listing = \HivePress\Models\Listing::query()->get_by_id($listing_id);
    $user_id = $listing->get_author__id();

    $user_listings = \HivePress\Models\Listing::query()->filter(['author__id' => $user_id])->count();
    if ($user_listings === 1) {
        (new \HivePress\Models\Message())->fill([
            'sender' => $user->get_id(),
            'sender__display_name' => $user->get_display_name(),
            'sender__email' => $user->get_email(),
            'recipient' => $user_id,
            'read' => 0,
            'text' => 'Hello world.',
        ])->save();
    }
}, 10, 2);


Or instead of sending a private message via the hivepress messages plugin, I could solve it directly by sending an email after adding an listing. I found this code of @andrii Email notification for paid listing confirmation and listing submission - General - HivePress Community which works, but I would like the title of the listing to be displayed instead of Custom subject and the ID of the listing to be displayed instead of Custom text, for example: Hello, Your listing was published with ID: 123

I found the following tokens somewhere, but I don’t know how to use them in the code:

'tokens'    => [
								'user'          => $user,
								'listing'       => $listing,
								'user_name'     => $user->get_display_name(),
								'listing_title' => $listing->get_title(),
								'listing_url'   => get_permalink( $listing->get_id() ),
							],```

Please try to debug the code making sure that you’re using the existing hooks, functions, etc. For example, there’s no “author” field in listings, there’s a “user” field though hivepress/includes/models/class-listing.php at master · hivepress/hivepress · GitHub So this method may always return an empty value unless there’s a custom attribute named “author”:

$listing->get_author__id()

You can customize the New Message email but there’s no simple snippet, it’s more complex because messages are sent in 2 contexts, via the listing page (with the “New reply to [listing_name]” subject) or directly via the conversation page or vendor page (with “New Message” subject).

I recommend using the hivepress/v1/emails/message_send hook and check if the listing token is not empty, if not then you can change subject or body parameters based on this token for the email.

Hope this helps

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.