Hi @wortep
How can we determine the first import of goods to a site? So that the status of a novelty is added to new products. Now the new status is added to all goods, including the very first import. The first goods must be imported without a novelty.
I am not sure where you’re storing the new status, but couldn’t you just leave it out when you first create the import? After the first run you can edit the import template and add the new status, then go to the import settings and use the “Choose which data to update” option to disable the field that you’re adding the new status in. This way it’s only imported for new products on subsequent runs.
If you want to do it all automatically, then you could use the pmxi_saved_post hook: https://github.com/soflyy/wp-all-import-action-reference/blob/master/all-import/pmxi_saved_post.php. Example code:
function my_saved_post( $post_id, $xml_node, $is_update ) {
global $wpdb;
$import_id = ( isset( $_GET['id'] ) ? $_GET['id'] : ( isset( $_GET['import_id'] ) ? $_GET['import_id'] : 'new' ) );
if ( $import = $wpdb->get_row( $wpdb->prepare( "SELECT <code>iteration</code> FROM <code>" . $wpdb->prefix . "pmxi_imports</code> WHERE <code>id</code> = '%d'", $import_id ) ) ) {
if ( $import->iteration > 1 && ! $is_update ) {
// $post_id is a new post and this is not the first run of the import
// add novelty to the post programmatically here
// e.g.: update_post_meta( $post_id, '_is_new_product', 'true' );
}
}
}
add_action('pmxi_saved_post', 'my_saved_post', 10, 3);
How we can add our checkbox for set new product status ?
Unfortunately there’s no way to add a checkbox in the location your screenshot shows, but you could write an add-on with a radio option in the import template: https://www.wpallimport.com/documentation/addon-dev/overview/.