• Resolved Drazen

    (@dadodd)


    Hi,

    I am interested if is it possible to import only items that do not exist already ( post, products), for example check by title or sku and if the item exist skip this item, if it doesn’t exist import item as new?

    Thanks

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

    (@wpallimport)

    Hi @dadodd

    The easiest way to do this would be to use manual record matching: https://www.wpallimport.com/documentation/recurring/manual-record-matching/. With this, existing posts will be updated with the data in your file, and new posts will be created, depending on these settings: https://d.pr/bVlioA (note: the delete option won’t be available when using manual record matching).

    Alternatively, if you’re using a “New Items” import, you can utilize our wp_all_import_is_post_to_create hook: https://github.com/soflyy/wp-all-import-action-reference/blob/master/all-import/wp_all_import_is_post_to_create.php.

    Here’s an example that will skip the record if the SKU already exists (based on the {sku[1]} element) in WooCommerce:

    function my_is_post_to_create( $continue_import, $xml_node, $import_id ) {
        global $wpdb;
        $query = "SELECT <code>meta_value</code> FROM <code>&quot; . $wpdb->prefix . &quot;postmeta</code> WHERE <code>meta_key</code> = '_sku' AND <code>meta_value</code> = '" . $xml_node['sku'] . "'";
        $results = $wpdb->get_results( $query );
        return ( empty( $results ) ) ? true : false;
    }
    add_filter( 'wp_all_import_is_post_to_create', 'my_is_post_to_create', 10, 3 );
    Thread Starter Drazen

    (@dadodd)

    Thank you very much, I will try.
    Should I put this code in theme functions.php or inside WPI php block on Import page?

    Thank you

    Plugin Author WP All Import

    (@wpallimport)

    Hi @dadodd

    Either one should work, but I’d suggest using our function editor so that you don’t lose it when you update your theme.

    Im tryng to do same thing, my sku node is called pleaser_item

    i changed it and put in editor but does still create already existent sku

    where is my error?

    function my_is_post_to_create( $continue_import, $xml_node, $import_id ) {
       if ( $import_id == 55 ) { // Change this to the ID of your import
        global $wpdb;
        $query = "SELECT <code>meta_value</code> FROM <code>&quot; . $wpdb->prefix . &quot;postmeta</code> WHERE <code>meta_key</code> = '_sku' AND <code>meta_value</code> = '" . $xml_node['pleaser_item'] . "'";
        $results = $wpdb->get_results( $query );
    	   echo $results;
        return ( empty( $results ) ) ? true : false;
    	   }
    }
    add_filter( 'wp_all_import_is_post_to_create', 'my_is_post_to_create', 10, 3 );
    Thread Starter Drazen

    (@dadodd)

    I think I solved this in settings by putting create new products, check by SKU. For existing products do no update nothing or update only price.

    Or you can alternatively try code provided by support.

    putting code and check by sku simply create new product without sku when wpallimport find duplicate

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Import only non existing item’ is closed to new replies.