I'd like to know if there's a way to assign a default value in the Price field in Drupal Commerce. Currently, there are no field settings available.
It is not possible for the default price field, because Drupal locks down the field / widget settings for "locked" fields. This is a general Drupal issue, but you could work around it by using an alternate price field that you add custom to your product type paired with a product pricing rule that swaps that price in at the start of the pricing process. You'd have to do a form alter or something to hide the default price field from your product forms.
You can temporarily unlock the field, set the default price and lock it again. The PHP code is as follows:
$field = field_read_field('commerce_price'); $field['locked'] = 0; // 0: unlock; 1: lock. field_update_field($field);
You could run it using drush eval (use backslash to escape the $ and put it all on one line) or the php block from the devel module. Credit: http://atlantic-canary.net/en/how-to-lockunlock-a-field-in-drupal.
Don't forget to lock it again after to make the field safe again.
Instill devel module Enable the devel module either by drush en or from admin/build/modules. It will generate several blocks and look for the one named ‘Execute PHP’ enable it by setting it to a preferred region . Write the code you want to check on the text area for example and then press execute to see the result.
so here we will use this code
$field_name = 'field_name';
$field = field_read_field($field_name);
$field['locked'] = 0; // 0: unlock; 1: lock.
note: this line $field_name = 'field_name'; you have to add your filed name for example like this $field_name = commerce_price;
if you got any error such as displayed as messages “Notice: Undefined index” or “Notice: Undefined variable” and your logs will grow insanely…
the solution is to add in your settings.php the line
ini_set('error_reporting', 'E_ALL ^ E_NOTICE');