In the Ubercart D7 uc attribute module I am trying to run code on the fieldset attribute if the product is a specific product class in the module with an if statement.

This calls an if for payment received

      if ($op == 'update' && $order->order_status == 'payment_received' && $arg2 == 'completed') { 
// ... your code goes here 


How do I call it for a product class??

In uc_attributes module at

   function uc_attribute_uc_form_alter(&$form, &$form_state, $form_id) {
  //. other code of module's function... 
    $element[$key]['#type'] = 'fieldset';
    //    if (product class . ..) {
  // ... your code goes here

So that only the validate code runs on the field set if the product is the same product class

I have rest of the code largely ready to go

2 Answers 2


The node type is Ubercart class. Because, then you create a new class in /admin/store/products/classes it will create the new content type in /admin/structure/types So code will like next:

if ($op == 'update' && $order->order_status == 'payment_received' && $arg2 == 'completed') {
  if (is_array($order->products)) {
    foreach ($order->products as $product) {
      if ($product->type == 'SOMECLASS') {
         // DO something
  • Yes, Nikit, Thanks this is what I was after. Someone downvoted this so I upvoted back to zero. My question was not clear - I am calling this inside the uc_attributes module at the function uc_attribute_uc_form_alter - so I am guessing I do not need the foreach loop. I am trying to operate on the fieldset textfield to regulate and validate what can be entered there, using ajax and callback throwing form errors for this class of product before allowing the product to be added to the cart. I am working on it - it will be tricky to get to work because I do not think I can nest functions Apr 25, 2021 at 16:47
  • @wilburunion catch my vote up :) About ajax - I assume it should be another question or search here for answers.
    – Nikit
    Apr 25, 2021 at 23:23

The function to use is:


This returns a boolean variable indicating whether the node is a product type.

  • Not trying to test - I know the class - it already exists, I think Nikit answered what I needed Apr 25, 2021 at 16:49
  • If you're just trying to check to see if a node is of a specific known type, then that's not even an Ubercart question.
    – anonymous
    Apr 25, 2021 at 17:38
  • Nikit answered it. I wanted the syntax to call a specific product class in the if statement in a module Apr 26, 2021 at 14:55
  • Yes, I understand, but that is NEVER necessary if all you want to do is add validation for a textfield attribute for a specific product class in Ubercart. You asked the wrong question, and you are heading down the wrong path.
    – anonymous
    Apr 27, 2021 at 6:21
  • OK - so how do you propose it must be done since JQuery, Ajax and php code functions must be done on the text field as characters are typed and then error out preventing an add to cart if the field is not valid?? Apr 28, 2021 at 11:07

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.