我可以使用下面的代码显示属性值但是如果该属性为空它只打印出单词" No"
<?php echo $_product->getResource()->getAttribute('c_address')->getFrontend()->getValue($_product); ?>
答案 0 :(得分:1)
要获取customer属性,您可以这样使用:
$customerRepository = $objectManager->get('Magento\Customer\Api\CustomerRepositoryInterface');
$customer = $customerRepository->getById(1);
$cattrValue = $customer->getCustomAttribute('c_address');
要获取产品属性,您可以像这样使用:
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Catalog\Model\Product')->load('YOUR PRODUCT ID');
echo $product->getAttributeText('your_attribut');
答案 1 :(得分:1)
最简单的方法是
$customer = $CUSTOMER_OBJECT; // GET customer object
$customer->getCustomAttribute('variable_name')->getValue();