Automattic\WooCommerce\Internal\Orders
OrderActionsRestController::get_available_email_templates
Determine which email templates are available for the given order.
Method of the class: OrderActionsRestController{}
Hooks from the method
Returns
WC_Email[].
Usage
// private - for code of main (parent) class only $result = $this->get_available_email_templates( $order ): array;
- $order(WC_Order) (required)
- The order in question.
OrderActionsRestController::get_available_email_templates() OrderActionsRestController::get available email templates code WC 10.7.0
private function get_available_email_templates( WC_Order $order ): array {
$all_email_templates = WC()->mailer()->emails;
$order_status = $order->get_status( 'edit' );
$unavailable_statuses = array(
OrderStatus::AUTO_DRAFT,
OrderStatus::DRAFT,
OrderStatus::NEW,
OrderStatus::TRASH,
);
if ( ! $order->get_billing_email() || in_array( $order_status, $unavailable_statuses, true ) ) {
return array();
}
$valid_template_classes = array(
'WC_Email_Customer_Invoice',
);
if ( $this->order_is_partially_refunded( $order ) ) {
$valid_template_classes[] = 'WC_Email_Customer_Refunded_Order';
}
if ( isset( self::STATUS_TEMPLATE_MAP[ $order_status ] ) ) {
$valid_template_classes[] = self::STATUS_TEMPLATE_MAP[ $order_status ]['class'];
}
/**
* Filter the list of valid email templates for a given order.
*
* Note that the email class must also exist in WC_Emails::$emails.
*
* When adding a custom email template to this list, a callback must also be added to trigger the sending
* of the email. See the `woocommerce_rest_order_actions_email_send` action hook.
*
* @since 9.8.0
*
* @param string[] $valid_template_classes Array of email template class names that are valid for a given order.
* @param WC_Order $order The order.
*/
$valid_template_classes = apply_filters(
'woocommerce_rest_order_actions_email_valid_template_classes',
$valid_template_classes,
$order
);
$valid_template_classes = array_filter( array_unique( $valid_template_classes ), 'is_string' );
$valid_templates = array_fill_keys( $valid_template_classes, '' );
return array_intersect_key( $all_email_templates, $valid_templates );
}