0

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

1

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!

6
  • Yes we can apply condition
    – ZealousWeb
    Aug 23 at 13:11
  • I have updated my answer with condition
    – ZealousWeb
    Aug 23 at 13:14
  • 1
    If it is useful for you then please upvote and approve so other members can use it :)
    – ZealousWeb
    Aug 23 at 13:29
  • I have updated my code, can we reduced this gap (height) between attribute and product name ? If yes please share that code (piece of line.) Thanks Aug 24 at 6:10
  • 1
    Yes , i will share in few minutes
    – ZealousWeb
    Aug 24 at 6:51

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.