Magento 2.3 – How to Retrieve Multi-Select Custom Product Attribute Value

magento2.3product-attribute

I created a new drop-down custom product attribute and placed it in an attribute set. and I'm trying to retrieve its value programmatically in Magento 2. The name of said attribute is "ee_qty_custom" but for some reason, I always get either 1 or an empty array when I use any and all functions including:

  1. getattribute('ee_qty_custom')
  2. getattributetext('ee_qty_custom')
  3. getData('ee_qty_custom')

Here is the code for some of what I tried
enter image description here

Best Answer

You can get the atrribute value by:

<?php echo $_product->getEeCustomQty();?>
<?php echo $_product->getattributetext('ee_custom_qty');?>

First code will give you the value of option and second one will give you text. Both code should work.

Tip: If your code is not showing on front, make sure you set Used in Product Listing to yes in Storefront Properties of attribute!

Related Topic