• Resolved shortik

    (@shortik)


    Hi,
    is there a way to set stock status “out of stock” for products that are no longer in the feed?
    My situation:
    I have several feeds that I’m importing. Sometimes my suppliers delete product from feed. I want to set stock status to “out of stock” for the deleted product. I don’t want to delete it. Is there a way for that?
    The very last option I want to do is to make a new table with productID and feed/supplier attributes and program function that will insert relevant information to that table and that will be call from some hook in WP all import. Is there more simple way to do what I need?
    Thanks
    Shortik

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author WP All Import

    (@wpallimport)

    Hey @shortik,

    is there a way to set stock status “out of stock” for products that are no longer in the feed?

    You can enable “Delete products that are no longer present in your file” in the import settings, then write custom code that uses our wp_all_import_is_post_to_delete hook to set the stock status and then return false to stop the deletion. Here’s an example of how that hook is used: https://www.wpallimport.com/documentation/code-snippets/#prevent-some-posts-from-being-deleted-by-wp-all-import.

    Thread Starter shortik

    (@shortik)

    Hi,
    I made the code like this. Will see if it works. Thanks for your reply.

    add_filter('wp_all_import_is_post_to_delete', 'set_out_of_stock_when_missing_in_feed', 10, 3);
    
    function set_out_of_stock_when_missing_in_feed($is_post_to_delete, $post_id, $import)
    {
      wc_update_product_stock_status($post_id, 'outofstock');
      return false;
    }

    @shortik does it work?

    Thread Starter shortik

    (@shortik)

    When I tried to make a new import for some feed and checked the “Delete products that are no longer present in your file” I see built-in function that set “out of stock” instead of deletion… Picture.
    Now it seems I can use that function but when I set “Unique identifier” for product SKU, what is in the feed, the import creates new products. Where WP All import stores data about what products was imported by specific import? Can I fill some table in database to pair products from old import to new import so WP all import will skip creating files that are already in database?

    Plugin Author WP All Import

    (@wpallimport)

    Hi @shortik,

    When I tried to make a new import for some feed and checked the “Delete products that are no longer present in your file” I see built-in function that set “out of stock” instead of deletion… Picture.

    My apologies, that’s the correct option to use and it’s much easier.

    Where WP All import stores data about what products was imported by specific import? Can I fill some table in database to pair products from old import to new import so WP all import will skip creating files that are already in database?

    That’s tracked in the “pmxi_posts” database table. Technically you could update it to associate products with different imports, but there’s no supported way to do that and it has the potential to cause issues.

    Instead, I’d suggest using custom code and our API to prevent duplicates, for example: https://www.wpallimport.com/documentation/code-snippets/#do-not-create-products-with-duplicate-sku.

    Or, if you’re not working with variable products (i.e. you’re not importing new variations), you could use an “Existing Items” import: https://www.wpallimport.com/documentation/update-existing-posts/.

    Plugin Author WP All Import

    (@wpallimport)

    Hey @shortik,

    This thread has been inactive for a while, so I’m going to mark it as complete. Please start a new topic if you still have questions.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Set out of stock for products that are no longer in the feed’ is closed to new replies.