• I think I may have found a bug with how the plugin/woocommerce handles bundled products which have previously been added to a cart but move to draft status since.

    Normally if a product is in a user’s cart but is moved to draft status before they checkout woocommerce removes the product from their cart automatically. What I’ve found is that if a user adds a bundled product to their cart but doesn’t complete checkout, and an admin then moves the product in draft status – the parent product is removed from cart but the bundled products remain orphaned in the cart as “ghost items”, i.e they’re not visible in the cart and they aren’t charged for, but they appear in the admin dashboard.

    This had been a problem for a client of mine because their accounting and warehouse operated in isolation, so there were times when the warehouse would see these “ghost items” on the print out and pack the order, unaware that the items had not been paid for.

    I have been able to resolve this by hooking into checkout and looping over cart items to check if any bundled products are orphaned(their bundle parent is not present in the cart), but I think this warrants some further investigation and a fix as it could lead to loss of income for stores.

Viewing 6 replies - 1 through 6 (of 6 total)
  • @jasonduvenage We habe the same problem. How did you solve this? ??

    Cheers

    • This reply was modified 3 years, 8 months ago by niikk.
    Thread Starter jasonduvenage

    (@jasonduvenage)

    This code could be improved and there are probably better hooks to use but I was having a hard time with them and in a hurry, this works for me though.

    add_action('woocommerce_check_cart_items', 'remove_orphaned_bundled_products_from_cart', 20);
    add_action('woocommerce_before_checkout_process', 'remove_orphaned_bundled_products_from_cart', 20);
    function remove_orphaned_bundled_products_from_cart( $array ) {
      $cart_items = WC()->cart->get_cart();
    
      $bundled_products = array_map(function($product) {
        if(isset($product['woosb_parent_id']) && !empty($product['woosb_parent_id'])) {
          return [
            'product_id' => $product['product_id'],
            'woosb_parent_id' => $product['woosb_parent_id'],
            'key' => $product['key'],
          ];
        }
      }, $cart_items);
    
      $product_ids = array_map(function($product) {
        return $product['product_id'];
      }, $cart_items);
    
      foreach ($cart_items as $cart_item) {
        if( get_post_status( $cart_item['product_id'] ) === "draft" ) {
          foreach ($bundled_products as $bundled_product) {
            if($bundled_product['woosb_parent_id'] === $cart_item['product_id']) {
              WC()->cart->remove_cart_item( $bundled_product['key'] );
            }
          }
          WC()->cart->remove_cart_item( $cart_item['key'] );
        }
    
        if(isset($cart_item['woosb_parent_id']) && !empty($cart_item['woosb_parent_id']) && !in_array($cart_item['woosb_parent_id'], $product_ids)) {
          WC()->cart->remove_cart_item( $cart_item['key'] );
        }
      }
    }

    @jasonduvenage

    Thanks!! I also faced a other issue with draft products: (https://www.ads-software.com/support/topic/issue-with-product-in-draft-or-review-status/)

    Did you have this also on your end?

    Cheers

    • This reply was modified 3 years, 8 months ago by niikk.
    Thread Starter jasonduvenage

    (@jasonduvenage)

    I haven’t encountered that problem so far, which is not to say it isn’t a bug. I can’t say for sure but I would look at trying to override the is_in_stock method of the bundled product class to check for child products which are in draft status.

    Having same issue guys. We found out a lot of orders that we lost money and our pickers picked the ghost items!! Maybe 10-15 orders per day last month.
    Urgent issue

    Hi guys,
    I am sorry for late response!
    Thanks for informing me on this issue! I’ve fixed this issue on version 5.5.3. Please update the plugin to the latest version and try again.
    Best regards,

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Possible Bug with Draft Product and Cart’ is closed to new replies.