2022 October preBFCM Marketplace Sale

Import as draft, not published

My client imports new products from LS every couple of weeks, maybe adding 10 or 20 at a time. As she imports them, she immediately, goes and changes the Woo products (post) from “published” to “draft” — as she likes to manage images and descriptions in WP. So she doesn’t want them live immediately on import before she has added the description etc. So an option to “Import as draft” somewhere in the loaded products table would be great. Alternatively: I can see where the insert_post array is created, and the quicker fix for now might be to just have a filter on that, so a developer could change that to ‘status’ => ‘draft’

Current Status

Closed

Last updated: August 15, 2022

6 comments

Log in to comment on this feature request.

  1. Bob Passaro says:

    Looks like this was done! Awesome. Thanks.

  2. conschneider says:

    Hi there,

    I d love to just chime in and say, thanks! 🙂 However we have not added an extra option “Import as draft” and imported products still get published immediately. Furthermore with the recent release, custom database tables were introduced: https://docs.woocommerce.com/document/woocommerce-lightspeed-pos/#section-18

    How do you handle this at the moment?

    Kind regards,

  3. Bob Passaro says:

    Oh, sorry, just noticed this, conschneider. Well I meant there is now a filter hook on the array where the Product post is created, so I can hook in and change ‘status’ => ‘draft’ without having to hack the plugin file 🙂

    I swear that hook wasn’t there when I made the original request, but maybe it was and I missed it.

  4. Bob Passaro says:

    Pretty simple snippet now for anyone who is interested:

    /**
    * Filter insert post array on import so that products come in as draft, not published.
    */

    add_filter( ‘wclsi_import_post_fields_matrix_prod’, ‘mystore_import_product_as_draft’ );
    add_filter( ‘wclsi_import_post_fields_single_prod’, ‘mystore_import_product_as_draft’ );

    function mystore_import_product_as_draft( $import_fields ) {
    $import_fields[‘post_status’] = ‘draft’;
    return $import_fields;
    }

  5. Anonymous says:

    Here’s another awesome way to do it (disclaimer: partially tested so far, but promising):

    add_filter( ‘wp_insert_post_data’, ‘post_insert_handler’, ’99’, 2 );
    function post_insert_handler($data,$postarr) {
    if (strpos($data[“post_type”],”product”)===0) $data[“post_status”] = “draft”;
    return $data;
    }

  6. adriano03b3472dbd says:

    I am running into problems with the importer (which I believe to be unrelated) however I am attempting to do this in the CSV file. I have a column labelled “Published” which I assign a value of `-1 (which is what one of my draft items exported as) and I’m attempting to run the importer. Will this work or will this cause issues?

WooCommerce

The most customizable eCommerce platform for building your online business.

  • 30-day money-back guarantee
  • Support teams across the world
  • Safe and secure online payment