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