How to add product features’ values to order notifications sent by email

Problem

Add product features’ values to order notifications sent by email.

Solution

Edit the notification template in section Store → Settings → Notifications.

  1. Before the line

    {foreach $order.items as $item}

    add this code snippet:

    {$features_products = []}
    {$items_product_ids = []}
    {$items_products = []}
    
    {foreach $order.items as $item}
        {$product = $wa->shop->product($item.product_id)}
    
        {if $product.name|default:''}
            {$features_products[$item.product_id] = $product}
            {$items_product_ids[$item.id] = $item.product_id}
        {/if}
    {/foreach}
    
    {if $features_products}
        {$features = $wa->shop->features($features_products)}
    {/if}
    
    {if $features}
        {foreach $order.items as $item}
            {if !empty($items_product_ids[$item.id])}
                {$items_products[$item.id] = $features_products[$item.product_id]}
            {/if}
        {/foreach}
    {/if}
    
  2. Between the lines

    {foreach $order.items as $item}

    and

    {/foreach}

    add this code snippet in the desired location where feature values must be displayed:

    {if !empty($items_products[$item.id].features)}
        <ul>
            {foreach $items_products[$item.id].features as $feature_code => $feature_value}
                {if !empty($features[$feature_code])}
                    <li>
                        {$features[$feature_code].name|escape}: 
                        {if is_array($feature_value)}
                            {implode(', ', $feature_value)|escape}
                        {else}
                            {$feature_value|escape}
                        {/if}
                    </li>
                {/if}
            {/foreach}
        </ul>
    {/if}

    For instance, immediately below the this part of template code:

    <p style="
        font-style:normal;
        font-variant:normal;
        font-weight:normal;
        font-size: {if $_is_service}12{else}14{/if}px;
        line-height:16px;
        font-family:Helvetica,Arial,sans-serif;
        ">
        {if !$_is_service}
            <a href="{$item.product.frontend_url|default:'javascript:void(0);'}">
                <font style="text-decoration: underline;">{if $_is_service}+ {/if}{$item.name|escape}</font>
                {if !empty($item.sku_code)} <font style="color: #aaaaaa; font-size: 0.8em;">{$item.sku_code|escape}</font>{/if}
            </a>
        {else}
            {if $_is_service}+ {/if}{$item.name|escape}
            {if !empty($item.sku_code)} <font style="color: #aaaaaa; font-size: 0.8em;">{$item.sku_code|escape}</font>{/if}
        {/if}
        {if !empty($item.download_link)}<a href="{$item.download_link}"><strong>Скачать</strong></a>{/if}
    </p>

0 comments

    Add comment

    To add a comment please sign up or login