Support » Plugin: Import any XML or CSV File to WordPress » Check for duplicate prodocts SKU

  • Resolved sejkan

    (@sejkan)


    Hi Dear,
    I have struggling with duplicate SKU products for a while.
    The problem is that plugin checks for duplicate sku and dont create new products in same ID import, but if we have same sku in another import ID it create new one, and put SKU as BLANK.

    Could you please help me, is there some function to check if there is SKU duplicate.
    If we cannot disable importing duplicate SKU, I want to echo some value and create custom field that I know which products are duplicate in my woocommerce.

    Thank you.

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

    (@wpallimport)

    Hi @sejkan

    You can use the WooCommerce filter ‘wc_product_has_unique_sku’ for this. Here’s an example snippet:

    add_filter('wc_product_has_unique_sku', 'wpai_wc_product_has_unique_sku', 10, 3);
    function wpai_wc_product_has_unique_sku($sku_found, $product_id, $sku) {
            if ($sku_found){
            	// Duplicate SKU found.
            }
    	return $sku_found;
    }

    Hi Dear,
    How to implement this to WP ALL IMPORT.

    add_filter('wc_product_has_unique_sku', 'wpai_wc_product_has_unique_sku', 10, 3);
    function wpai_wc_product_has_unique_sku($sku_found, $product_id, $sku) {
            if ($sku_found){
            	echo 'Duplicate';
            } else {
    	return $sku;
    }
    }
    

    OR somtehing else*

    • This reply was modified 7 months, 3 weeks ago by  sejkan.
    Plugin Author WP All Import

    (@wpallimport)

    Hi @sejkan

    If you’re just wanting to log a message in the import history log, then something like this should work:

    add_filter( 'wc_product_has_unique_sku', 'wpai_wc_product_has_unique_sku', 10, 3 );
    function wpai_wc_product_has_unique_sku( $sku_found, $product_id, $sku ) {
        if ( $sku_found ) {        	
            $m = '[' . date( "H:i:s", time() ) . '] Duplicate SKU found for product ID ' . $product_id . ': ' . $sku;
            echo '<div class="progress-msg">' . $m . '</div>';
        }
        return $sku_found;
    }

    Thank you for answer. This is helpfull too.
    What I need is to call this function and get value in my custom field.

    EXAMPLE:
    [wpai_wc_product_has_unique_sku({SKU[1]})]

    Result TRUE: This Sku is duplicate
    Result FALSE: This Sku is not duplicate

    Thank you a lot

    • This reply was modified 7 months, 3 weeks ago by  sejkan.
    Plugin Author WP All Import

    (@wpallimport)

    Hi @sejkan

    What I need is to call this function and get value in my custom field.

    You should just use update_post_meta() to add a custom field to the product using the function above.

    If you want to do it from within the import template, then you’ll have to write a custom function that checks for a duplicate SKU. Example:

    function my_is_sku_unique( $sku ) {
    	return ( $product = wc_get_product_id_by_sku( $sku ) ) ? 'the sku already exists' : 'the sku does not exist';
    }

    Thank you a lot,
    You have one of the best support on market.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Check for duplicate prodocts SKU’ is closed to new replies.