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’
Closed
Last updated: August 15, 2022
Log in to comment on this feature request.
If you stumble upon this post just like me. Looking for a solution to import products from a csv file as a draft. But you don’t use the Lightspeed POS Integration, I have made this snippet that does work with native Woocommerce. Read the instructions here: https://codump.github.io/#e5f3b46d96e0ad4574a7ea1ddd60ee3a
set_status( ‘draft’ );
return $product;
}
?>
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?
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;
}
Looks like this was done! Awesome. Thanks.
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,
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.
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;
}