I am using a 3rd party plugin for order number customization and the format I am using is- {order id}-{counter}AB e.g. 1234-30000AB

In the email template when I include order id variable it is picking the whole order number, i.e. 1234-30000AB whereas I only want to include the first four digits, i.e., 1234.

Is there a way I can create a string filter to remove last the last 7 digits



Observed event email_order_set_template_vars_before and add your new increament id and create new order email template from existing one and update it accordingly.


<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
  <event name="email_order_set_template_vars_before">
    <observer name="add_extra_data_to_transport" instance="Vendor\Module\Observer\AddExtraDataToTransport" />



namespace Vendor\Module\Observer;

use Magento\Framework\Event\ObserverInterface;

class AddExtraDataToTransport implements ObserverInterface
    public function execute(\Magento\Framework\Event\Observer $observer)
        $transport = $observer->getEvent()->getTransport();
        $order = $transpost['order'];
        $transport['new_increament_id'] = substr($order->getIncreamentId(), 0, 4);

Create a new email template by loading existing one and change $order.increment_id to $new_increament_id. I am sure it'll work. Let me know if you need further assistance for the same.

Happy Coding :)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.