diff --git a/includes/commerce_product.inline_entity_form.inc b/includes/commerce_product.inline_entity_form.inc
index 627818a..37204cf 100644
--- a/includes/commerce_product.inline_entity_form.inc
+++ b/includes/commerce_product.inline_entity_form.inc
@@ -118,6 +118,7 @@ class CommerceProductInlineEntityFormController extends EntityInlineEntityFormCo
     $defaults = parent::defaultSettings();
     $defaults['autogenerate_title'] = TRUE;
     $defaults['use_variation_language'] = FALSE;
+    $defaults['delete_references'] = FALSE;
 
     return $defaults;
   }
@@ -139,6 +140,11 @@ class CommerceProductInlineEntityFormController extends EntityInlineEntityFormCo
       '#title' => t('Refer to the referenced products as "variations"'),
       '#default_value' => $this->settings['use_variation_language'],
     );
+    $form['delete_references'] = array(
+      '#type' => 'checkbox',
+      '#title' => t('Delete referenced entities when all parents nodes has been deleted.'),
+      '#default_value' => $this->settings['delete_references'],
+    );
 
     return $form;
   }
diff --git a/inline_entity_form.module b/inline_entity_form.module
index 393cb26..0b1e3d7 100644
--- a/inline_entity_form.module
+++ b/inline_entity_form.module
@@ -1030,3 +1030,94 @@ function inline_entity_form_pre_render_add_fieldset_markup($form) {
 
   return $form;
 }
+
+/**
+ * Implements hook_entity_delete().
+ *
+ * Delete entities referenced on node, only if it is the last reference.
+ */
+function inline_entity_form_entity_delete($entity, $type) {
+  if ($type != 'node') {
+    return;
+  }
+  $entity_info = entity_get_info($type);
+  if (!empty($entity_info['entity keys']['bundle']) && isset($entity->$entity_info['entity keys']['bundle'])) {
+    $fields_info = field_info_fields();
+    $bundle_key = $entity_info['entity keys']['bundle'];
+    $wrapper = entity_metadata_wrapper($type, $entity);
+    // Retrive all entities referenced in commerce_product_reference field.
+    foreach (field_info_instances($type, $entity->$bundle_key) as $field_name => $field) {
+      if ($field['widget']['type'] == 'inline_entity_form' && $fields_info[$field_name]['type'] == 'commerce_product_reference' && $field['widget']['settings']['type_settings']['delete_references'] == TRUE) {
+        $settings = inline_entity_form_settings($fields_info[$field_name],$field);
+        $entity_type = $settings['entity_type'];
+        foreach($wrapper->$field_name->value() as $referenced_entity) {
+          if (!_entity_is_referenced($referenced_entity, $entity_type)) {
+            // Delete the entity if it is not referenced in another node.
+            $entity_info = entity_get_info($entity_type);
+            $id_key = $entity_info['entity keys']['id'];
+            entity_delete($entity_type, $referenced_entity->$id_key);
+          }
+        }
+      }
+    }
+  }
+}
+
+/**
+ * Determine if another node reference this entity.
+ *
+ * @param $entity
+ * @param $type
+ *
+ * @return bool
+ *   TRUE if another reference has been found, otherwise FALSE.
+ */
+function _entity_is_referenced($entity, $type) {
+  $entity_info = entity_get_info($type);
+  $id_key = $entity_info['entity keys']['id'];
+  $candidates = &drupal_static(__FUNCTION__);
+  if (!isset($candidates[$type])) {
+    $fields_info = field_info_fields();
+    $widget_info = field_info_widget_types('inline_entity_form');
+    $candidates[$type] = array();
+    $bundle_key = !empty($entity_info['entity keys']['bundle'])? $entity_info['entity keys']['bundle']: FALSE;
+    // Gather all fields which can reference this entity type.
+    foreach(field_info_instances('node') as $bundle => $fields) {
+      foreach ($fields as $field_name => $field) {
+        if (in_array($fields_info[$field_name]['type'], $widget_info['field types'])) {
+          $settings = inline_entity_form_settings($fields_info[$field_name],$field);
+          $bundlesMatch = (!empty($settings['bundles']) && $bundle_key) ? in_array($entity->$bundle_key, $settings['bundles']): TRUE;
+          if ($settings['entity_type'] == $type && $bundlesMatch) {
+            $sql_column = $settings['column'];
+            $sql_table = key($fields_info[$field_name]['storage']['details']['sql'][FIELD_LOAD_CURRENT]);
+            $sql_field = $fields_info[$field_name]['storage']['details']['sql'][FIELD_LOAD_CURRENT][$sql_table][$sql_column];
+            $candidates[$type][$sql_table] = array(
+              'sql_table' => $sql_table,
+              'sql_field' => $sql_field,
+            );
+          }
+        }
+      }
+    }
+  }
+
+  // Query all candidate fields to see if there is more than one reference.
+  $queries = $candidates[$type];
+  $query = array_shift($queries);
+  $sub = db_select($query['sql_table'], $query['sql_table'] . '_')
+    ->fields($query['sql_table'] . '_', array($query['sql_field']))
+    ->condition($query['sql_field'], $entity->$id_key);
+  foreach($queries as $query) {
+    $s = db_select($query['sql_table'], $query['sql_table'] . '_')
+      ->fields($query['sql_table'] . '_', array($query['sql_field']))
+      ->condition($query['sql_field'], $entity->$id_key);
+    $sub->union($s,'ALL');
+  }
+
+  $count = db_select($sub)
+    ->countQuery()
+    ->execute()
+    ->fetchField();
+
+  return $count == 1 ? FALSE: TRUE;
+}
\ No newline at end of file
