0

I found simple code to put inside custom module that prints extra field inside cart view table

<?php
function ucaddsku_form_alter(&$form, $form_state, $form_id) {
if ($form_id == 'uc_cart_view_form') {
$form['items']['#columns']['model']['cell'] = 'SKU';
        for($i=0;$i<count(uc_cart_get_contents());$i++){            
        $form['items'][$i]['model']['#value'] = node_load($form['items'][$i]['nid']['#value'])->model . ": "; 

    }
}
}
?>

How can be any cck field printed like this?

1

You can print the cck field like this.

// Load the node.
$node = node_load($nid);

// Print the fields.
print $node->title;
print $node->field_myfield[LANGUAGE_NONE][0]['value'];

or a more decent way like this...

$myfield = field_get_items('node', $node, 'field_myfield');

https://api.drupal.org/api/drupal/modules!field!field.module/function/field_get_items/7

See this also. https://api.drupal.org/api/drupal/modules%21field%21field.module/function/field_view_value/7

| improve this answer | |
  • Hi, is it the code same for drupal 6? – loparr Jun 5 '13 at 23:25
  • 1
    For Drupal 6 use print $node->field_myfield[0]['value'];, or loop over $node->field_myfield if there are multiple items – Clive Jun 5 '13 at 23:36

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.