post_status in Woocommerce default CSV exporter/importer

This is what I have tried to export/import the post_status with the default Woocommerce CSV importer/exporter.

I have managed to get the post_status field to show up mapped in the importer/exporter. It also exports the column to csv. However there is no data.

How could I get the post_status to export and import correctly?

// ADD CUSTOM IMPORT COLUMN TO CSV IMPORTER
add_filter( 'woocommerce_csv_product_import_mapping_options', 'add_column_to_importer' );

function add_column_to_importer ( $options ) {
    $options['post_status'] = 'post_status';
    return $options;
}

add_filter( 'woocommerce_csv_product_import_mapping_default_columns', 'add_column_to_mapping_screen' );

function add_column_to_mapping_screen ( $columns ) {
    $columns['post_status'] = 'post_status';
    return $columns;
}

add_filter( 'woocommerce_product_import_pre_insert_product_object', 'process_import', 10, 2 );

function process_import( $object, $data ) {    
    if (!empty($data['post_status'])) {
    $object->post_status($data['post_status']);
  }
    return $object;
}

// ADD CUSTOM EXPORT COLUMN TO CSV EXPORTER
add_filter( 'woocommerce_product_export_column_names', 'add_export_column' );
add_filter( 'woocommerce_product_export_product_default_columns', 'add_export_column' );

function add_export_column( $columns ) {    
    $columns['post_status'] = 'post_status';
    return $columns;
}

add_filter( 'woocommerce_product_export_product_column_custom_column', 'add_export_data', 10, 2 );

function add_export_data( $value, $product ) {
    $post_status = get_post_status();
    return $post_status;
}

Solutions

You have an issue inside your hooks. Check the last hook, for example. You need to replace ...._custom_column with your actual column which is in your case post_status:

add_filter( 'woocommerce_product_export_product_column_post_status', 'add_export_data', 10, 2 );

function add_export_data( $value, $product ) {
    return $product->get_status();
}

add_filter( 'woocommerce_product_import_pre_insert_product_object', 'process_import', 10, 2 );
function process_import( $product, $data ) {
    if ( ! empty( $data['post_status'] ) ) {
        $product->set_status( $data['post_status'] );
    }

    return $product;
}

This hook is used to add some data to your column and because the hook is incorrect, no data is visible.

Similar questions

WordPress CSV Importer takes a long time to finish
I have created a lot of custom CSV importers for WordPress in the past and I have come across issues related to the time it takes for them to finish processing. Whenever the importer starts running, it starts off importing a lot of posts per second but this speed keeps decreasing and I am trying to figure out the reason for this and if whether ther...
help with really simple csv importer
( sorry for the title, but i dont know how to explain this as a title ^^ ). I'm using really simple csv importer to bulk import data in my site, using Advanced custom fields. So i need to import some data as serialized data. So i used the hook "really_simple_csv_importer_save_meta_filter" as show in docs. But i have an issue, the hook just explain ...
Wordpress CSV Importer Plugin, Import file from url instead of upload file from pc
The wordpress plugin csv importer http://wordpress.org/extend/plugins/csv-importer/ works great for importing posts from csv. The plugin only supports browse file option to upload file from local pc while I want to upload file from file url. Is this possible? Can someone edit the plugin code so that it supports upload file from file url? Thanks,
How to import csv file via woocommerce import csv suite
I am totally new to WooCommerce. I was trying to import updated CSV file via import csv suite. Explanation : I have four fields in my table. Say name, email, age, and mobile number. Now I want to add two new fields to table like gender and income. I have added all six field to csv file and also added column to db table. but while importing it retur...
Creating a Wordpess Plugin that writes data to a csv file. The data doesn't show in the csv file?
I am writing my first Wordpress Plugin that should simply write data to a csv file. This is the code, I can't figure out why the data won't write to the csv file? Can someone explain to me why it won't work? And what i need to do so it will simply write the data to the csv file. I want the data to be dynamic so it will refresh the data in the csv f...
Create users by importing from CSV, with User ID assigned from CSV
I am in a situation where I need to import user data from another platform. Because, I have to keep associated userID for some reason, I have to keep user id as it is in the csv. I have tried using wp_insert_user() however, it work only for update and not for the new user if I pass the ID key in params array. Question: Is there any way to create us...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.