$shipping_class_slug = 'your-shipping-class-slug';
// get just the IDs of all products published
$products = new WP_Query( array (
'post_type' => 'product',
'posts_per_page' => -1,
'fields' => 'ids'
));
// for each product change the shipping class
foreach ( $products->posts as $pID ) {
wp_set_object_terms( $pID, $shipping_class_slug, 'product_shipping_class' );
}
Old answer
$shipping_class_slug = 'your-shipping-class-slug';
// get all products published
$products = new WP_Query( array (
'post_type' => 'product',
'posts_per_page' => -1
));
// retrieve products IDs
$productsIDs = wp_list_pluck( $products->posts, 'ID' );
// for each product change the shipping class
foreach ( $productsIDs as $pID ) {
wp_set_object_terms( $pID, $shipping_class_slug, 'product_shipping_class' );
}
1 回答
这应该会更改所有已发布帖子的运送类别 .
Updated answer
只记得fields参数,所以这是新代码:
Old answer
您可以将其包装在函数中(在functions.php文件中)以使用action进行调用 .
记得用你想要的改变
'your-shipping-class-slug'
.最重要的是: DO A BACKUP 在你尝试任何事情之前! ;)
(更好:在本地克隆网站并首先尝试)