Re: Hello Newb cousin!

Posts: 17
Joined: 05/03/2008

Hi Newbstah,

Many thanks. This was the way to do it, for sure.

I got some help over at #drupal-ubercart (a great irc community).

I'm going to list the steps here in the hope that it'll make someone else's life a bit easier.

I'm very thin on the ground with PHP and can only really alter working examples to achieve what I need to do.

Anyway, to get this working, I followed these steps:

• Add a CCK field to product page from: Administer > Content Management > Content Types

• Add a product and populate all your fields, including your added custom CCK field

• Place this code at the end of your node-product.tpl.php page:

<pre>
<?php // this will print the $node array at the bottom of each node take it out when finished ?>
<?php var_dump($node); ?>
</pre>

You'll find your node-product.tpl.php page in your working theme directory. This page can be customized to alter and theme your product pages.

Load a product page in your browser. At the end of the page you'll notice drupal has spat out a lot of raw PHP code. Through some trial and error, you need to pick up the PHP code which represents your custom CCK field.

Here's an example: $node->field_wholesale_details[0]['view']

• To display, theme or alter the display position of this field, you can use CSS and DIVs on your tpl.php page

• To hide this field based on whether or not a user is logged in, you can surround it with this code:

<?php
global $user;
if(
$user->uid != 0){
  print
$node->field_wholesale_details[0]['view'];
} else {
  print
"Log in to view wholesale information";
}
?>

As I understand it, the user id (uid) of 0 is assigned to anonymous users. So as per the above code, the field will only be displayed to users 1 >.

This is probably a rough way of doing this. I ideally wanted to create a custom module to achieve this, but I simply could not get it to work, after many weeks of effort and research.

Thanks to acm over at #drupal-ubercart for your help.

Hiding CCK field in Product View By: ubernewbie (7 replies) Mon, 05/12/2008 - 07:56