Skip to content
Docs
Get RestroPress

Function

Emails and email tags functions

Updated
On this page

Functions for order emails, email templates and the email tags available in them.

47 functions. Each entry shows the signature, parameters, return value and where it is defined. Functions marked internal are hook callbacks, screen renderers and other plumbing that extensions normally do not call.

rpress_trigger_purchase_receipt()#

Sends the order receipt email when an order completes.

Hooked to rpress_complete_purchase at priority 999. Skips sending while an order is being edited in the admin (rpress-action is edit_payment). Calls rpress_email_purchase_receipt() with the admin notice enabled.

rpress_trigger_purchase_receipt( $payment_id = 0, $payment = null, $customer = null )

Parameters

ParameterTypeDefaultDescription
$payment_idint0Order (payment) ID.
$paymentRPRESS_Payment|nullnullPayment object for the order.
$customerRPRESS_Customer|nullnullCustomer object. Not used by the function.

Internal. Defined in includes/emails/actions.php, line 24.

rpress_resend_purchase_receipt()#

Resends the order receipt email from the order history screen.

Hooked to rpress_email_links. Reads purchase_id from the request data, requires the edit_shop_payments capability (otherwise ends with a 403 wp_die), sends the receipt without the admin notice, redirects with rpress-message=email_sent and exits.

rpress_resend_purchase_receipt( $data )

Parameters

ParameterTypeDefaultDescription
$dataarrayRequiredRequest data; purchase_id is the order ID to resend.

Note: Ends the request with a redirect and exit. The email query argument is read but not used as the recipient.

Internal. Defined in includes/emails/actions.php, line 40.

rpress_send_test_email()#

Handles the Send Test Email link after verifying the rpress-test-email nonce.

Hooked to rpress_send_test_email. Returns silently if the nonce check fails, otherwise calls rpress_email_test_purchase_receipt(), redirects back without the rpress_action argument and exits.

rpress_send_test_email( $data )

Parameters

ParameterTypeDefaultDescription
$dataarrayRequiredRequest data containing _wpnonce.

Internal. Defined in includes/emails/actions.php, line 74.

send_customer_purchase_notification()#

Emails the customer when an order moves to a status with notifications enabled.

Hooked to rpress_update_order_status. Reads the status settings with rpress_get_option( $new_status ) and sends via rpress_email_purchase_receipt() without the admin notice when enable_notification is set. Does nothing for the pending status or an empty payment ID.

send_customer_purchase_notification( $payment_id, $new_status )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.
$new_statusstringRequiredNew order status slug.

Note: Not prefixed with rpress_.

Internal. Defined in includes/emails/actions.php, line 85.

rpress_add_email_tag()#

Registers an email tag that is replaced in email content.

Delegates to RPRESS()->email_tags->add(). The tag is stored only if $func is callable. When {tag} is found in content, the callback receives the order ID and the tag name and must return the replacement string. Register tags on the rpress_add_email_tags action.

rpress_add_email_tag( $tag, $description, $func )

Parameters

ParameterTypeDefaultDescription
$tagstringRequiredTag name, without braces.
$descriptionstringRequiredDescription shown in the list of available tags.
$funccallableRequiredCallback that returns the replacement text.

Example

add_action( 'rpress_add_email_tags', function () {
	rpress_add_email_tag( 'order_total_plain', 'Order total as plain text', function ( $payment_id ) {
		return rpress_get_payment_amount( $payment_id );
	} );
} );

Defined in includes/emails/email-tags.php, line 23.

rpress_remove_email_tag()#

Removes a registered email tag.

Delegates to RPRESS()->email_tags->remove().

rpress_remove_email_tag( $tag )

Parameters

ParameterTypeDefaultDescription
$tagstringRequiredTag name, without braces.

Example

add_action( 'rpress_add_email_tags', function () {
	rpress_remove_email_tag( 'phone' );
}, 20 );

Note: Run it after the tag has been registered, for example on rpress_add_email_tags with a priority later than 10.

Defined in includes/emails/email-tags.php, line 33.

rpress_email_tag_exists()#

Checks whether an email tag is registered.

rpress_email_tag_exists( $tag )

Parameters

ParameterTypeDefaultDescription
$tagstringRequiredTag name, without braces.

Returns bool: True if the tag is registered.

Defined in includes/emails/email-tags.php, line 45.

rpress_get_email_tags()#

Returns all registered email tags.

Each entry is an array with the keys tag, description and func, keyed by tag name.

rpress_get_email_tags()

Returns array: Registered tags keyed by tag name.

Defined in includes/emails/email-tags.php, line 55.

rpress_get_emails_tags_list()#

Returns the registered email tags as an HTML list string.

Each line has the form {tag} - description followed by a br tag. Returns an empty string when no tags are registered.

rpress_get_emails_tags_list()

Returns string: HTML string listing the tags.

Note: Returns the markup; it does not echo it.

Defined in includes/emails/email-tags.php, line 65.

rpress_do_email_tags()#

Replaces registered email tags in a string for an order.

Delegates to RPRESS()->email_tags->do_tags(), then runs the result through the rpress_email_template_tags filter for backward compatibility. Unregistered tags are left untouched.

rpress_do_email_tags( $content, $payment_id )

Parameters

ParameterTypeDefaultDescription
$contentstringRequiredText containing tags such as {name}.
$payment_idintRequiredOrder (payment) ID.

Returns string: Content with the tags replaced.

Example

$subject = rpress_do_email_tags( 'Order #{order_id} for {name}', $payment_id );

Defined in includes/emails/email-tags.php, line 92.

rpress_load_email_tags()#

Fires the rpress_add_email_tags action so tags can be registered.

Hooked to init at priority -999.

rpress_load_email_tags()

Internal. Defined in includes/emails/email-tags.php, line 105.

rpress_setup_email_tags()#

Registers the default RestroPress email tags.

Hooked to rpress_add_email_tags. Each tag is mapped to its rpress_email_tag_* callback.

rpress_setup_email_tags()

Internal. Defined in includes/emails/email-tags.php, line 114.

rpress_email_tag_fooditem_list()#

Returns the HTML table of ordered menu items for the {fooditem_list} tag.

Builds the output from the order's cart details with output buffering. Item names can be hidden through the rpress_email_show_names filter.

rpress_email_tag_fooditem_list( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.

Returns string: HTML markup of the items, add-ons, subtotal, fees, tax, discount and total.

Internal. Defined in includes/emails/email-tags.php, line 244.

rpress_email_tag_first_name()#

Returns the customer's first name for the {name} tag.

Uses rpress_get_email_names() on the order's user_info.

rpress_email_tag_first_name( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.

Returns string: The first name, or the email address when no name is stored.

Internal. Defined in includes/emails/email-tags.php, line 402.

rpress_email_tag_fullname()#

Returns the customer's full name for the {fullname} tag.

Uses rpress_get_email_names() on the order's user_info.

rpress_email_tag_fullname( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.

Returns string: First and last name; empty if no name is stored.

Internal. Defined in includes/emails/email-tags.php, line 415.

rpress_email_tag_username()#

Returns the customer's username for the {username} tag.

Uses rpress_get_email_names() on the order's user_info.

rpress_email_tag_username( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.

Returns string: The user login for registered customers, otherwise the first name or email.

Internal. Defined in includes/emails/email-tags.php, line 428.

rpress_email_tag_user_email()#

Returns the customer's email address for the {user_email} tag.

rpress_email_tag_user_email( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.

Returns string: The email address of the order.

Internal. Defined in includes/emails/email-tags.php, line 441.

rpress_email_tag_delivery_address()#

Returns the delivery address for the {delivery_address} tag.

Reads the _rpress_delivery_address order meta and expects the keys address, city and postcode; flat is optional.

rpress_email_tag_delivery_address( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.

Returns string: Address, optional flat, then city and postcode, separated by newlines.

Note: Expects the meta to be an array. Orders without it can trigger PHP notices.

Internal. Defined in includes/emails/email-tags.php, line 452.

rpress_email_tag_billing_address()#

Returns the billing address for the {billing_address} tag.

Built from the order's address fields line1, line2, city, zip, state and country.

rpress_email_tag_billing_address( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.

Returns string: Billing address parts joined by spaces, with the country on a new line.

Internal. Defined in includes/emails/email-tags.php, line 468.

rpress_email_tag_date()#

Returns the order date for the {date} tag.

rpress_email_tag_date( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.

Returns string: Date formatted with the site's date_format option.

Internal. Defined in includes/emails/email-tags.php, line 500.

rpress_email_tag_subtotal()#

Returns the formatted order subtotal for the {subtotal} tag.

rpress_email_tag_subtotal( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.

Returns string: Subtotal with the currency symbol applied.

Internal. Defined in includes/emails/email-tags.php, line 512.

rpress_email_tag_tax()#

Returns the formatted tax amount for the {tax} tag.

rpress_email_tag_tax( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.

Returns string: Tax amount with the currency symbol applied.

Internal. Defined in includes/emails/email-tags.php, line 524.

rpress_email_tag_price()#

Returns the formatted order total for the {price} tag.

rpress_email_tag_price( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.

Returns string: Total with the currency symbol applied.

Internal. Defined in includes/emails/email-tags.php, line 536.

rpress_email_tag_phone()#

Returns the customer's phone number for the {phone} tag.

rpress_email_tag_phone( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.

Returns string: The phone value from the order meta, or an empty string.

Internal. Defined in includes/emails/email-tags.php, line 543.

rpress_email_tag_service_type()#

Returns the service type label for the {service_type} tag.

Reads the service type with rpress_get_service_type() and converts it with rpress_service_label().

rpress_email_tag_service_type( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.

Returns string: The label for the order's service type.

Internal. Defined in includes/emails/email-tags.php, line 551.

rpress_email_tag_service_time()#

Returns the scheduled service time for the {service_time} tag.

rpress_email_tag_service_time( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.

Returns string: The value of the _rpress_delivery_time order meta; empty if not set.

Internal. Defined in includes/emails/email-tags.php, line 558.

rpress_email_tag_order_note()#

Returns the customer's order note for the {order_note} tag.

rpress_email_tag_order_note( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.

Returns string: The _rpress_order_note value with tags stripped and HTML-escaped; empty if not a scalar.

Internal. Defined in includes/emails/email-tags.php, line 565.

rpress_email_tag_order_id()#

Returns the order number for the {order_id} tag.

rpress_email_tag_order_id( $order_id )

Parameters

ParameterTypeDefaultDescription
$order_idintRequiredOrder (payment) ID.

Returns string: The order number from rpress_get_payment_number().

Internal. Defined in includes/emails/email-tags.php, line 580.

rpress_email_tag_store_address()#

Returns the store address for the {store_address} tag.

The order ID is not used.

rpress_email_tag_store_address( $order_id )

Parameters

ParameterTypeDefaultDescription
$order_idintRequiredOrder (payment) ID. Not used.

Returns string: The store_address setting, or an empty string.

Internal. Defined in includes/emails/email-tags.php, line 591.

rpress_email_tag_receipt_id()#

Returns the order key for the {receipt_id} tag.

rpress_email_tag_receipt_id( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.

Returns string: The order's payment key.

Internal. Defined in includes/emails/email-tags.php, line 606.

rpress_email_tag_payment_method()#

Returns the payment method label for the {payment_method} tag.

rpress_email_tag_payment_method( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.

Returns string: The checkout label of the gateway used for the order.

Internal. Defined in includes/emails/email-tags.php, line 617.

rpress_email_tag_sitename()#

Returns the site name for the {sitename} tag.

The order ID is not used.

rpress_email_tag_sitename( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID. Not used.

Returns string: The site name from get_bloginfo( 'name' ).

Internal. Defined in includes/emails/email-tags.php, line 628.

Returns a link to the browser-based receipt for the {receipt_link} tag.

rpress_email_tag_receipt_link( $payment_id )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.

Returns string: An anchor tag with the text 'View it in your browser.' pointing to the home URL with payment_key and rpress_action=view_receipt.

Internal. Defined in includes/emails/email-tags.php, line 639.

rpress_email_purchase_receipt()#

Builds and sends the order email to the customer for a given order status.

Uses the subject, heading and body configured for the status, with email tags applied. Applies the filters rpress_purchase_from_name, rpress_purchase_from_address, rpress_purchase_subject, rpress_purchase_heading, rpress_receipt_attachments and rpress_receipt_headers. When $admin_notice is true it fires rpress_admin_order_notice.

rpress_email_purchase_receipt( $payment_id, $admin_notice = true, $to_email = '', $payment = null, $order_status = '' )

Parameters

ParameterTypeDefaultDescription
$payment_idintRequiredOrder (payment) ID.
$admin_noticebooltrueWhether to also fire the admin notification action.
$to_emailstring''Recipient address. Defaults to the order's email.
$paymentRPRESS_Payment|nullnullPayment object; loaded from the ID when null.
$order_statusstring''Status slug whose email template is used. Defaults to the order's current status.

Example

rpress_email_purchase_receipt( $payment_id, false, 'kitchen@example.com' );

Note: The result of the send is not returned.

Defined in includes/emails/functions.php, line 25.

rpress_email_test_purchase_receipt()#

Prepares the test receipt email settings from the admin.

Builds the from name, from email, heading and body with the default receipt settings and sets them on RPRESS()->emails, but the function does not call send().

rpress_email_test_purchase_receipt()

Note: In this version no email is sent by this function.

Internal. Defined in includes/emails/functions.php, line 72.

rpress_admin_email_notice()#

Sends the new order notification to the admin recipients.

Hooked to rpress_admin_order_notice. Returns early unless the admin_notification setting has enable_notification, the ID is non-zero and the order exists. Applies the filters rpress_admin_order_from_address, rpress_admin_order_notification_subject, rpress_admin_order_notification_heading, rpress_admin_order_notification_attachments and rpress_admin_order_notification_headers.

rpress_admin_email_notice( $payment_id = 0, $payment_data = array() )

Parameters

ParameterTypeDefaultDescription
$payment_idint0Order (payment) ID.
$payment_dataarrayarray()Order meta passed to the filters.

Internal. Defined in includes/emails/functions.php, line 99.

rpress_get_admin_notice_emails()#

Returns the email addresses that receive admin order notifications.

Uses the admin_recipients value of the admin_notification setting (one address per line), falling back to the admin_notice_emails option and then the site admin email. Filtered through rpress_admin_notice_emails.

rpress_get_admin_notice_emails()

Returns array: List of trimmed email addresses.

Example

foreach ( rpress_get_admin_notice_emails() as $address ) {
	error_log( $address );
}

Defined in includes/emails/functions.php, line 152.

rpress_get_default_sale_notification_email()#

Returns the admin sale notification text.

Returns the order_notification option when set, otherwise a built-in plain-text default that uses the {fooditem_list}, {name}, {price} and {payment_method} tags.

rpress_get_default_sale_notification_email()

Returns string: Notification message text.

Defined in includes/emails/functions.php, line 168.

rpress_get_email_names()#

Returns the name variants used in emails for a customer.

Without a payment object, reads user_info (serialized strings containing objects other than stdClass yield empty values). With an RPRESS_Payment, reads names from it. For registered users the username is the user login.

rpress_get_email_names( $user_info, $payment = false )

Parameters

ParameterTypeDefaultDescription
$user_infoarray|stringRequiredOrder user info array or serialized string.
$paymentRPRESS_Payment|falsefalsePayment object to read names from instead.

Returns array: Array with the keys name, fullname and username.

Example

$names = rpress_get_email_names( array(), rpress_get_payment( $payment_id ) );

Note: The fullname key is an empty string when no first name is available.

Defined in includes/emails/functions.php, line 193.

rpress_get_email_templates()#

Returns the registered email templates.

Creates a new RPRESS_Emails object and returns its get_templates() result.

rpress_get_email_templates()

Returns array: Template slugs mapped to labels.

Defined in includes/emails/template.php, line 22.

rpress_email_template_tags()#

Applies email tags to a message.

Wrapper around rpress_do_email_tags(). The $payment_data and $admin_notice arguments are ignored.

rpress_email_template_tags( $message, $payment_data, $payment_id, $admin_notice = false )

Parameters

ParameterTypeDefaultDescription
$messagestringRequiredMessage containing tags.
$payment_dataarrayRequiredNot used.
$payment_idintRequiredOrder (payment) ID.
$admin_noticeboolfalseNot used.

Returns string: Message with tags replaced.

Note: Kept for backward compatibility; prefer rpress_do_email_tags().

Defined in includes/emails/template.php, line 38.

rpress_email_preview_template_tags()#

Replaces tags in a message with sample values for the preview.

Substitutes sample data for tags such as {fooditem_list}, {name}, {price} and {receipt_link}. Filtered through rpress_email_preview_template_tags, and passed through wpautop unless rpress_email_template_wpautop returns false.

rpress_email_preview_template_tags( $message )

Parameters

ParameterTypeDefaultDescription
$messagestringRequiredMessage containing tags.

Returns string: Message with sample values.

Internal. Defined in includes/emails/template.php, line 48.

rpress_email_template_preview()#

Outputs the Preview Order Receipt and Send Test Email buttons.

Hooked to rpress_purchase_receipt_email_settings. Does nothing without the manage_shop_settings capability.

rpress_email_template_preview()

Note: Echoes output instead of returning it. The buffered markup is passed through esc_html before output.

Internal. Defined in includes/emails/template.php, line 88.

rpress_display_email_template_preview()#

Renders the receipt email preview and exits.

Hooked to template_redirect. Runs only when rpress_action is preview_email and the user has manage_shop_settings.

rpress_display_email_template_preview()

Note: Echoes the built email and calls exit.

Internal. Defined in includes/emails/template.php, line 106.

rpress_get_email_body_content()#

Returns the email body for an order status.

Uses the content saved for the status, or for pending orders the purchase_receipt option, falling back to a built-in HTML template. Applies wpautop unless rpress_email_template_wpautop returns false, then the filters rpress_purchase_receipt_{template} and rpress_purchase_receipt. Tags are not replaced here.

rpress_get_email_body_content( $payment_id = 0, $payment_data = array(), $order_status='' )

Parameters

ParameterTypeDefaultDescription
$payment_idint0Order (payment) ID.
$payment_dataarrayarray()Order meta passed to the filters.
$order_statusstring''Status slug to use. Defaults to the order's current status.

Returns string: Email body with tags still in place.

Example

$body = rpress_do_email_tags( rpress_get_email_body_content( $payment_id ), $payment_id );

Defined in includes/emails/template.php, line 129.

rpress_get_order_notification_body_content()#

Returns the admin notification body for an order.

Uses the admin_notification content when enabled, else the order_notification option, else a built-in default listing items, customer, amount and payment method. Tags are replaced, wpautop is applied unless rpress_email_template_wpautop returns false, and the result is filtered by rpress_sale_notification.

rpress_get_order_notification_body_content( $payment_id = 0, $payment_data = array() )

Parameters

ParameterTypeDefaultDescription
$payment_idint0Order (payment) ID.
$payment_dataarrayarray()Order meta passed to the filter.

Returns string: Notification body.

Defined in includes/emails/template.php, line 226.

rpress_render_receipt_in_browser()#

Renders the order receipt as a standalone page and exits.

Hooked to rpress_view_receipt. Requires the payment_key query argument, otherwise ends with wp_die. Sends no-cache headers and fires rpress_render_receipt_in_browser_before and rpress_render_receipt_in_browser_after.

rpress_render_receipt_in_browser()

Note: Outputs a full HTML page and calls die().

Internal. Defined in includes/emails/template.php, line 269.

Was this page helpful?