We have a site with over 1200 sku's that are wrong and we want to delete them all without affecting the products.
Is there a quicker way to do this via the db in phpmyadmin.
Any help would be great.
Thanks
We have a site with over 1200 sku's that are wrong and we want to delete them all without affecting the products.
Is there a quicker way to do this via the db in phpmyadmin.
Any help would be great.
Thanks
Here is your solution. change post per page argument and post meta values for sku. (Not tested)
https://www.themelocation.com/how-to-updateadd-sku-of-all-products-in-woocommerce/
add_action( 'init', 'update_sku', 10, 1);
function update_sku( $sku ){
$args = array(
'post_type' => 'product',
'posts_per_page' => -1
);
$i=0;
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
$random_sku = mt_rand(100000, 999999);
update_post_meta($loop->post->ID,'_sku','');
$i++;
endwhile;
} else {
echo __( 'No products found' );
}
wp_reset_postdata();
}