• I don’t know what wrong when plugin create sku. When i called get_product_id_by_sku() it’s not work.
    I can get sku by get_post_meta(post_id, ‘_sku’) but get_product_id_by_sku() not work.
    After a few hours investigating i found a solution.

    Woocommerce has another table to get sku it’s wc_product_meta_lookup

    So i run this code:

    global $wpdb;
    
    $all_ids = get_posts( array(
    	'post_type' => 'product',
    	'numberposts' => -1,
    	'post_status' => 'publish',
    	'fields' => 'ids',
    ) );
    foreach($all_ids as $id){
    	$wpdb->update( 
    		$wpdb->wc_product_meta_lookup, 
    		array( 
    			'sku' => get_post_meta($id, '_sku', true),
    		), 
    		array( 'product_id' => $id)
    	);
    }
    

    I hope it will help.
    Thanks

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘get_product_id_by_sku funtion not work’ is closed to new replies.