Support » Plugin: WPAdverts - Classifieds Plugin » Email notification

  • Resolved Mikhail

    (@minus20)


    Hello again!

    My customer ask me to add email notification on posting ad. One for teh administrator about new ad and one for the user who posted the ad with payment details, advert id and publishing length.

    Is there built in functionality for this? If not, can i make it with custom plugin?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Greg Winiarski

    (@gwin)

    Hi, you can do that using a plugin like Better Notifications for WordPress https://wordpress.org/plugins/bnfw/ or by using post status transitions https://codex.wordpress.org/Post_Status_Transitions

    
    add_action( "publish_advert", "on_advert_publish" );
    function on_advert_publish( $post_id ) {
        $to = get_post_meta( $post_id, "adverts_email", true );
        $advert = get_post( $post_id );
        wp_mail( $to, "Ad Published", sprintf( "Your ad %s has been published", $advert->post_title ) );
    }
    
    bnfw

    (@voltronik)

    Hi @minus20,
    Thought i’d chime in and say that BNFW and WPAdverts can work well together.
    Here’s some more details: https://betternotificationsforwp.com/documentation/compatibility/wpadverts-plugin/

    @voltronik, but can i include generated price and ID of advert?

    • This reply was modified 1 year, 9 months ago by Mikhail.
    Plugin Author Greg Winiarski

    (@gwin)

    You should be able to get the ID like with any other post (with [ID] tag), the price is inside the adverts_price meta field, but i am not sure if meta fields are supported in BNFW.

    @gwin, i’ve created simple plugin and it works on publishing, but i can’t make it work on pending. Is there some special sort of action? Documentation says we can use something like this {status}_{post_type}, but pending_advert didn’t work. And in the database we have status advert_pending.

    Also tried advert_tmp_to_pending, new_advert

    I found another post, just like my: “Email notification when new listing is created”. But like it described there, pending_advert didn’t work in my case.

    • This reply was modified 1 year, 8 months ago by Mikhail.
    • This reply was modified 1 year, 8 months ago by Mikhail.
    • This reply was modified 1 year, 8 months ago by Mikhail.
    • This reply was modified 1 year, 8 months ago by Mikhail.
    Plugin Author Greg Winiarski

    (@gwin)

    What action to use depends on your workflow, the pending_advert should work with free Ads.

    If you are using default Payments Module try advert-pending_advert.

    If you are using WC Payments then the action should be wc_pending_advert.

    Yes! It works! Thank you very much @gwin!

    Here is my sample code so anyone can use it:

    
    function wp_acen_on_advert_new( $post_id ) {
            /* collect data for mail content
    	$advert = get_post( $post_id );
    	$post_title = $advert->post_title;
            /* etc.. any meta data */
    
    	$content = <<<TEXT
    Mail content
    TEXT;
    
    	$subject = 'Your classifieds Ads created on site <website>';
    	$headers = 'Content-Type: text/html; charset: UTF-8';
    
    	wp_mail($user_email, $subject, $content, $headers);
    }
    
    add_action( "advert-pending_advert", "wp_acen_on_advert_new" );
    
Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Email notification’ is closed to new replies.