Get Credit memo details by order id programmatically Magento 2.

You can get the Credit memo collection details for the specific order by an order id using Magento 2.

Using Magento\Sales\Api\CreditmemoRepositoryInterface interface, you need to use getList() function to fetch no. of credit memo by sales order id.

Using SearchCriteriaBuilder Class, You need to filter by order id and pass search criteria object to getList() method of CreditmemoRepositoryInterface.

Database Table used the store the credit memo data:
sales_creditmemo

Call from a template or other class by,

Output:

The array of Credit memo collection for a Specific Order.