Programmatically Add Features for Role assignment in Ubercart Drupal 7 product node I am trying to create a product programmatically and set it features for role assignment, that a user gets a specific role after he purchases, i tried all the ways i can but couldnt get it working. below is the code i used for adding it, but when i edit the feature for role assignment it doesnt hold the values i set in the edit feature form.

function add_product_feature($nid, $sku){
     // Insert new product into the uc_product_features tables
     $desc = "&lt;strong&gt;SKU:&lt;/strong&gt; ".$sku."&lt;br /&gt;&lt;strong&gt;Role:
     &lt;/strong&gt;purchaser&lt;br /&gt;&lt;strong&gt;Expiration:&lt;/strong&gt; &lt;a 
      href=\"/admin/store/settings/products\"&gt;Global expiration&lt;/a&gt; 
      (not overridden)&lt;br /&gt;&lt;strong&gt;Shippable:&lt;/strong&gt; No&lt;br /&gt;
      &lt;strong&gt;Multiply by quantity:&lt;/strong&gt; No";
      $nid1 = db_insert('uc_product_features')
      -&gt;fields(array('nid' =&gt; $nid,'fid' =&gt; 'role','description' =&gt; 
      $desc, 
      ))
      -&gt;execute();
}
Don't do that. Inserting into the DB directly can cause you problems down the road; there's already been code written to do what you're trying to do.

Look at the uc_roles functions/documentation and follow how it adds product features via uc_roles_feature_form_submit submission handler and its uc_product_feature_save() call.