Skip to content

Instantly share code, notes, and snippets.

@alidemirci
Last active March 5, 2020 13:03
Show Gist options
  • Save alidemirci/5aadcd62bb0085ba615a4dd92fde95a5 to your computer and use it in GitHub Desktop.
Save alidemirci/5aadcd62bb0085ba615a4dd92fde95a5 to your computer and use it in GitHub Desktop.
Update All WooCommerce product SKUs
// 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 );
}
}
@alidemirci
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment