send_email_notification

πŸ“… Published on

πŸ“ Last updated

Documentation

Β»

Functions

Β»

send_email_notification

Queues a Groundhogg email template to be sent to a contact. The email is added to the event queue and dispatched on the next cron run. This is the recommended way to send transactional emails from outside a funnel. You can schedule the send for a future time by passing a Unix timestamp or parseable date string as the third argument β€” omitting it queues the email to send immediately on the next run.

Parameters

ParameterTypeDescription
$email_idint|EmailThe ID of a published Groundhogg email template, or an Email object.
$contact_id_or_emailint|string|ContactThe recipient β€” accepts a contact ID, email address, or Contact object.
$timeint|stringUnix timestamp or parseable date string for when to send. Defaults to 0 (send on next queue run).

Return value

bool β€” true if the event was queued successfully, false on failure.

Usage

// Send immediately (next queue run)
\Groundhogg\send_email_notification( 123, 'jane@example.com' );

// Schedule for a specific time
\Groundhogg\send_email_notification( 123, $contact, strtotime( '+1 hour' ) );

Example

Here’s a pseudo code example for a hypothetical WooCommerce integration.

add_action( 'woocommerce_order_status_completed', 'my_plugin_send_post_purchase_email' );

/**
 * Send a Groundhogg follow-up email when a WooCommerce order is completed.
 *
 * @param int $order_id
 *
 * @return void
 */
function my_plugin_send_post_purchase_email( $order_id ) {

    $order   = wc_get_order( $order_id );
    $contact = \Groundhogg\get_contactdata( $order->get_billing_email() );

    if ( ! $contact ) {
        return;
    }

    \Groundhogg\send_email_notification( MY_PLUGIN_POST_PURCHASE_EMAIL_ID, $contact );
}

Was this helpful?

Let us know if this document answered your question. That’s the only way we can improve.