In Drupal Commerce, you can use the following to print out a field in your node.tpl.php file:

<?php print render($content['product:field_NAME']); ?>

See here fore more information

But how do you print a field only if it has content?

For a normal Drupal field you would use the following:

<?php if (isset ($node->field_NAME)): ?>
  <?php print $node->field_NAME['und'][0]['safe_value'];?>
<?php endif; ?> 

But that doesn't work with a Drupal commerce field.

I would appreciate if someone could offer any pointers!


Content for the referenced product fields is incorporated into the product display(node) using field_extra_fields and normally contents go into the #markup key.

You can use template_preprocess_node and use something like this:

if (!isset($variables['content']['product:field_NAME']['#markup'])) {

You could also try Field formatter conditions module.

| improve this answer | |

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.