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 ) );
}
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 5 years ago by
Mikhail.
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 5 years ago by
Mikhail.
-
This reply was modified 5 years ago by
Mikhail.
-
This reply was modified 5 years ago by
Mikhail.
-
This reply was modified 5 years ago by
Mikhail.
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" );