所以我进口了6000多种产品,我面临着一个问题。
问题是我没有父级SKU,所以当我导入所有变体时,我的第一个版本与父版本使用相同的SKU,所以当我更新价格时,它对我的第一个版本不起作用。
所以我只想从我所有的变体中移除父母的sku,然后用空白或随机替换它。
有可能吗?还是我要重新导入所有东西?
提前谢谢。
发布于 2022-09-20 10:21:32
将以下函数放入您的functions.php中。始终在大容量更改之前执行备份。这在WP 6.0.2 WC 6.9.2上进行了测试和工作。
// Change hook if needed. This will run on each refresh of the website
add_action('init','test');
function test() {
// Get variable products.
$args = array(
'type' => 'variable',
'return' => 'ids',
);
$product_ids = wc_get_products( $args );
foreach($product_ids as $product_id) {
// Get the current parent sku
$main_sku = get_post_meta( $product_id, '_sku', true );
// If not empty clear it
if(!empty($main_sku)) {
update_post_meta($product_id, '_sku', '');
}
}
}
https://stackoverflow.com/questions/73784016
复制相似问题