Useful Snippets

Update All WooCommerce product SKUs

Pinterest LinkedIn Tumblr
 // Please paste this code to your theme function file
 // Go to Admin Panel and refresh for once
 // Then remove this code from functions file

 add_action( 'init', 'amc_update_all_sku' );

 function amc_update_all_sku(){

	$products = wc_get_products( array(
		'limit' => -1
	) );

	foreach( $products as $product){

		// Set Product name as SKU
		$variable = esc_html( strtolower ( $product->name ) );
		$product->set_sku( $variable );

	}

 }

Write A Comment