Skip to main content

Give your add-on’s email a starting design in the Email Editor

Premium Intermediate

Filters what an email opens on in the editor when nothing is stored for it. Return [ 'blocks' => [ … ] ] for your own type; each block is { id, type, props, conditions }.

Code

<?php
add_filter( 'benecaster_email_editor_default_design', function ( ?array $design, string $type ): ?array {
    if ( 'my_addon_receipt' !== $type ) {
        return $design;
    }

    return [
        'blocks' => [
            [ 'id' => 'a', 'type' => 'heading', 'props' => [ 'text' => __( 'Thanks!', 'my-addon' ) ] ],
            [
                'id'         => 'b',
                'type'       => 'button',
                'props'      => [ 'label' => __( 'See your order', 'my-addon' ), 'url' => '{{order_url}}' ],
                // Core leaves a missing tag in the text as written, so a block with one tests it.
                'conditions' => [ [ 'type' => 'tag', 'tag' => 'order_url', 'when' => 'filled' ] ],
            ],
        ],
    ];
}, 10, 2 );

View on GitHub →

Hooks Used

Need this built rather than just documented? See our services →