Show Magento custom (yes/no) Attribute value in success.phtml

Show Magento custom (yes/no) Attribute value in success.phtml

September 18, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Show Magento custom (yes/no) Attribute value in success.phtml

Displaying Custom Yes/No Attribute Value on Magento’s Success Page

As a Magento developer, you often need to display customized information about an order, such as whether it contains a PDF product that the customer will receive via email. In this scenario, we’ll show how to retrieve and display the value of a custom Yes/No attribute on the success.phtml page.

Retrieving Order Information

First, let’s understand the provided code snippet for retrieving order information:

$order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);

$items = $order->getAllVisibleItems();
$itemcount=count($items);

foreach ($items as $itemId => $item)
{
    // Display item details
}

This code successfully retrieves the latest order and all its visible items. However, it fails to fetch custom Yes/No attribute values like pdf_ticket. Let’s fix this.

Accessing Custom Attributes

To access a custom Yes/No attribute in Magento, you need to use the correct getter method for that specific attribute. The attribute code is typically written in camelCase, so for an attribute named “PDF Ticket”, the getter would be getPdfTicket().

However, there seems to be a misunderstanding here—you’re trying to access the attribute using the wrong syntax:

$pdf = $item->getData('pdf_ticket');

This won’t work because ‘pdf_ticket’ is not recognized as an attribute’s name. Instead, Magento uses its own naming conventions for attributes.

Fetching Custom Yes/No Attributes

To fetch a custom Yes/No attribute correctly, you should:

  1. Ensure the attribute code matches Magento’s naming convention.
  2. Use the appropriate getter method (e.g., getPdfTicket()).

Assuming your attribute is named “PDF Ticket” and has an internal name of “pdf_ticket”, here’s how to fetch its value:

$order_id = Mage::getSingleton('checkout/session')->getLastRealOrderId();
$order = Mage::getModel('sales/order')->loadByIncrementId($order_id);

foreach ($order->getAllItems() as $item) {
    if ($item->getPdfTicket()) {
        // The item has a PDF ticket
    }
}

In this example, getPdfTicket() successfully retrieves the value of the “PDF Ticket” attribute.

Displaying Custom Messages

Now that you have the PDF ticket’s status, you can display a custom message on the success page:

foreach ($order->getAllItems() as $item) {
    if ($item->getPdfTicket()) {
        echo '<p>Thanks for ordering! Your PDF product should arrive in your inbox soon.</p>';
    }
}

This snippet checks if any item has a PDF ticket. If the attribute’s value is “Yes”, it displays the custom message.

Conclusion

In this guide, we’ve demonstrated how to retrieve and display the value of a Yes/No custom attribute on Magento’s success page using the correct getter methods and naming conventions.

Remember, always ensure your attributes follow Magento’s internal naming rules for successful data retrieval. If you need further assistance with customizing Magento’s checkout process or order management, feel free to explore our comprehensive Magento tutorials at LaravelCompany.com for more in-depth guidance.

Happy coding!

Checkout Catalog Themes Email

Our network