Skip Navigation

[Resolved] Sending Email "X" days before Value of Custom Date Field to Custom Email-Field P

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 3 replies, has 2 voices.

Last updated by alexanderW-6 10 months, 3 weeks ago.

Assisted by: Waqar.

Author
Posts
#2611727

Hi there,

is there any chance to trigger an wp-email-send (maybe by existing cronjob), that compares a custom field date to "now" and then send an email to the email-address of same custom post.

I don't really found something without users...

Thx, Alex

#2611877

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Alex,

Thank you for contacting us and I'd be happy to assist.

The Toolset plugins don't offer any built-in feature for this. So to achieve this you'll need some custom code solution.

Note: Since the value of "now" is constantly changing, a CRON job that is always running can have performance implications. A better approach would be to run it periodically, for example, once every hour, once every 30 minutes, or once every 15 minutes, etc.
( depending on the nature of the requirement )

Here are some useful guides on the topic:

hidden link
hidden link
hidden link
hidden link

For more personalized assistance around custom code, you can also consider hiring a professional from our list of recommended contractors:
https://toolset.com/contractors/

regards,
Waqar

#2611885

Hi there,
thx for your reply... The problem is not the trigger and that I already had and paid a code for a third-party-plugin, but I had to change this plugin and start to build it with toolset because, they couldn't fixe the date problems. I thought maybe it's just a slightly change to my values:

post-types, keys

but I'm not a coder and can't see, why it did not work

function prefix_get_bookings_ending() {

// How many days in advance should we send the email?
$days = 3;
$date = date( 'Y-m-d', strtotime( '+' . absint( $days ) . 'days' ) );
error_log( $date );

$args = array(
'post_type' => 'regal-buchung',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'wpcf-enddatum',
'value' => $date,
'compare' => '='
),
'fields' => 'ids'
);
$bookings = new WP_Query( $args );

// A list of bookings
$booking_ids = $bookings->posts;
if( $booking_ids ) {
foreach( $booking_ids as $booking_id ) {
prefix_send_reminder_email( $booking_id, $date );
}
}
wp_reset_postdata();

}
add_action( 'woocommerce_scheduled_sales', 'prefix_get_bookings_ending' );

//This function sends the email

function prefix_send_reminder_email( $booking_id, $end_date ) {

$booking_product_id = get_post_meta( $booking_id, 'wpcf-id-vom-regal', true );

$to = get_post_meta( $booking_id, 'wpcf-kundenemail', true );

$subject = __( 'Your booking', 'bfwc' );

ob_start();

wc_get_template( 'emails/email-header.php', array( 'email_heading' => $subject ) );

$content = ob_get_clean();

$message = sprintf(
'<p>%s<p>',
sprintf(
__( 'Your booking is coming to an end on %s', 'bfwc' ),
$end_date
)
);

$message = apply_filters( 'bfwc_reminder_email_content', $message, $booking_id );

$content .= $message;

ob_start();

wc_get_template( 'emails/email-footer.php' );

$content .= ob_get_clean();

wc_mail( $to, $subject, $content );

}

if not, than thx anyway

#2611977

Hi Waqar,

I found a solution myself... maybe some of the other Toolset-user may need this...

hidden link

changing time-range, different cron and a dynamic email-address:
$to = get_post_meta( get_the_ID(), 'a_custom_email', true );

Thx, Alex

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.