diff --git a/uc_wishlist.module b/uc_wishlist.module
index aaf5f8f..da7473f 100644
--- a/uc_wishlist.module
+++ b/uc_wishlist.module
@@ -326,65 +326,87 @@ function uc_wishlist_user_delete($account) {
  * of a wish list's owner, if items come from a single wish list.
  */
 function uc_wishlist_form_alter(&$form, &$form_state, $form_id) {
-  /**
-   * If user has access to create wishlist, allow him to add product into wishlist.
-   */
+  if ((strpos($form_id, 'uc_product_add_to_cart_form_') === 0) ||
+    (strpos($form_id, 'uc_product_kit_add_to_cart_form_') === 0)) {
 
-  if (user_access('create wish lists') && variable_get('uc_wishlist_out_of_stock', FALSE)) {
-    if ((strpos($form_id, 'uc_product_add_to_cart_form_') === 0) || (strpos($form_id, 'uc_product_kit_add_to_cart_form_') === 0)) {
-      // Add the wish list button to the add to cart form.
-      $form['actions']['wishlist'] = array(
-        '#type' => 'submit',
-        '#attributes' => array('class' => array('node-add-to-wishlist')),
-        '#value' => t('Add to wish list'),
-        '#submit' => array('uc_wishlist_add_to_wishlist_submit'),
-        '#weight' => 1,
-      );
+     /**
+      * If user has access to create wishlist, allow him to add product into
+      * wishlist.
+      */
+
+    if (!user_access('create wish lists'))
+      return;
+
+        /**
+        * If only in stock products can be added to the wishlist, check if we have
+        * stock, and if not, bail out.
+        */
+        if (!variable_get('uc_wishlist_out_of_stock', FALSE)) {
+      /**
+      * If stock module not enabled, or stock not active for this product, we
+      * don't care about stock.
+      */
+      if (module_exists('uc_stock')) {
+        $product = $form['node']['#value'];
+        $stock_level = uc_stock_level ($product->model);
+        if ($stock_level !== FALSE && $stock_level <= 0) {
+          return;
+		}
+      }
     }
+    // Add the wish list button to the add to cart form.
+    $form['actions']['wishlist'] = array(
+      '#type' => 'submit',
+      '#attributes' => array('class' => array('node-add-to-wishlist')),
+      '#value' => t('Add to wish list'),
+      '#submit' => array('uc_wishlist_add_to_wishlist_submit'),
+      '#weight' => 1,
+    );
+  }
 
-    /**
-     * Checking if the product is added from wishlist in checkout page.
-     */
-    if ($form_id == 'uc_cart_checkout_form') {
-      if (isset($form['panes']['cart']['cart_review_table']['#items']) && !empty($form['panes']['cart']['cart_review_table']['#items'])) {
-        $items = $form['panes']['cart']['cart_review_table']['#items'];
-        $wids = array();
-
-        foreach ($items as $item) {
-          if (!empty($item->data['wid'])) {
-            $wids[] = $item->data['wid'];
-          }
+  /**
+   * Checking if the product is added from wishlist in checkout page.
+   */
+  if ($form_id == 'uc_cart_checkout_form') {
+    if (isset($form['panes']['cart']['cart_review_table']['#items']) &&
+      !empty($form['panes']['cart']['cart_review_table']['#items'])) {
+      $items = $form['panes']['cart']['cart_review_table']['#items'];
+      $wids = array();
+
+      foreach ($items as $item) {
+        if (!empty($item->data['wid'])) {
+          $wids[] = $item->data['wid'];
         }
-        $wids = array_unique($wids);
+      }
+      $wids = array_unique($wids);
 
-        if (count($wids) > 1) {
-          drupal_set_message(t('This order contains items from multiple wish lists. It is not possible to automatically address this order for its recipient.'));
-        }
-        elseif (count($wids) == 1) {
-          $wishlist = uc_wishlist_load($wids[0]);
-
-          if (variable_get('uc_wishlist_save_address', TRUE) &&
-          !empty($wishlist->address->firstname) && !empty($wishlist->address->lastname) &&
-          !empty($wishlist->address->addr1) && !empty($wishlist->address->postcode) &&
-          is_object($form['panes']['delivery']['address']['#default_value']) &&
-          empty($form['panes']['delivery']['address']['#default_value']->delivery_first_name)) {
-            $order = uc_order_load($_SESSION['cart_order']);
-            if ($order) {
-              $defaults = $order;
-              $defaults->delivery_first_name = $wishlist->address->firstname;
-              $defaults->delivery_last_name = $wishlist->address->lastname;
-              $defaults->delivery_company = $wishlist->address->company;
-              $defaults->delivery_street1 = $wishlist->address->addr1;
-              $defaults->delivery_street2 = $wishlist->address->addr2;
-              $defaults->delivery_city = $wishlist->address->city;
-              $defaults->delivery_country = $wishlist->address->country;
-              $defaults->delivery_zone = $wishlist->address->zone;
-              $defaults->delivery_postal_code = $wishlist->address->postcode;
-              $defaults->delivery_phone = $wishlist->address->phone;
-              $form['panes']['delivery']['address']['#default_value'] = $defaults;
-
-              drupal_set_message(t('This order contains items from a wish list. The delivery address has been automatically set to the preferred address from the wish list. You may change this address.'));
-            }
+      if (count($wids) > 1) {
+        drupal_set_message(t('This order contains items from multiple wish lists. It is not possible to automatically address this order for its recipient.'));
+      }
+      elseif (count($wids) == 1) {
+        $wishlist = uc_wishlist_load($wids[0]);
+
+        if (variable_get('uc_wishlist_save_address', TRUE) &&
+        !empty($wishlist->address->firstname) && !empty($wishlist->address->lastname) &&
+        !empty($wishlist->address->addr1) && !empty($wishlist->address->postcode) &&
+        is_object($form['panes']['delivery']['address']['#default_value']) &&
+        empty($form['panes']['delivery']['address']['#default_value']->delivery_first_name)) {
+          $order = uc_order_load($_SESSION['cart_order']);
+          if ($order) {
+            $defaults = $order;
+            $defaults->delivery_first_name = $wishlist->address->firstname;
+            $defaults->delivery_last_name = $wishlist->address->lastname;
+            $defaults->delivery_company = $wishlist->address->company;
+            $defaults->delivery_street1 = $wishlist->address->addr1;
+            $defaults->delivery_street2 = $wishlist->address->addr2;
+            $defaults->delivery_city = $wishlist->address->city;
+            $defaults->delivery_country = $wishlist->address->country;
+            $defaults->delivery_zone = $wishlist->address->zone;
+            $defaults->delivery_postal_code = $wishlist->address->postcode;
+            $defaults->delivery_phone = $wishlist->address->phone;
+            $form['panes']['delivery']['address']['#default_value'] = $defaults;
+
+            drupal_set_message(t('This order contains items from a wish list. The delivery address has been automatically set to the preferred address from the wish list. You may change this address.'));
           }
         }
       }
