Last active
March 5, 2020 13:03
-
-
Save alidemirci/5aadcd62bb0085ba615a4dd92fde95a5 to your computer and use it in GitHub Desktop.
Update All WooCommerce product SKUs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Source