1

I want to add PHP field to View based on condition that certain logic field in content item is checked. How can I check that it is checked in PHP code?

More concisely: how can I check if some product's field is checked in Views?

The View is just showing list of contents

1
  • The question is very vague. Add some more information - e.g. which version of Drupal are you using, which shopping cart module are you using, what does the view do etc. Dec 5, 2013 at 7:03

2 Answers 2

1

I think you have not followed a correct way, these are the steps to create a custom field on the basis of value of an existing text field are :

  1. Add a field in any content type on basis of whose value you want to display a custom field.

  2. Add contents of that content type filling value of newly created field say its a checkbox having 0 or 1 as its value.

  3. Create a view of that content type.

  4. Add fields and a custom field having some value, say ;

    <?php 
    echo 'Astha Chauhan';
    ?>
    

    in output code field.

    1. Then add a filter of type Global:PHP and add a filter code accordingly:

        <?php    
            if ( $row->field_test_field == '2') {
             return $row->php; 
            }
            else { 
             return 'null'; 
            }  
         ?>
      
0

I guess you are using a product's field in your view based on whose value you want to add a custom field. Rite ???

  • If yes then add a field whose value you want to check in your view.
  • Then add a Global PHP field (note that the field whose value you want to check should be arranged prior to Glbal PHP field)
  • Add php logic there by using available tokens of previous field.
3
  • Mmm. I want to add custom field if one logic product's field is set to true. But products are displayed not considering this field value. So to say, I just want to add extra block to some products. Dec 5, 2013 at 7:31
  • Did you set value for this field in all your products ???? Dec 5, 2013 at 7:33
  • Yes, its value is set by default to 0, and on some products I set 1 and want to add extra field if it's so Dec 5, 2013 at 7:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.