Magento 2.4.0 – Add Custom Attribute Text in PDF Invoice After Product Name

invoicemagento2magento2.4product-attribute

How to i can add attribute text in pdf invoice after product name in Magento 2.4.0 ?

I am writing this code but not effecting.

$id = $item->getProductid();
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Catalog\Model\Product')->load($id);
$preorder =   $product->getAttributeText('preorder');

 if($preorder == "Yes") {
   $lines[][] = [
   'text' => $this->string->split('Pre Order', 10, true, true),
   'feed' => 125,
   'height' => 0,
    ];
  }

enter image description here

enter image description here

Best Answer

You need to add code like below. Please add your attribute value in below code.

$attributeVal = 1;

if($attributeVal == 1) {
    $lines[][] = [
        'text' => $this->string->split('Custom Attribute Value', 40, true, true),
        'feed' => 35,
    ];
}

Output :- https://prnt.sc/1qfmrpv

Cheers!

Related Topic