Все товары на моем сайте имеют 3 варианта. «1 упаковка», «2 упаковки» и «3 упаковки». Есть ли способ, чтобы быстро и временно установить все «1 пакет» на складе? У меня есть следующий код, но он дает мне ошибку.
$posts = get_posts(
array(
'post_type' => 'product_variation',
'numberposts' => 10,
'fields' => 'ids',
)
);
foreach($posts as $key => $value) {
$\ _child = wc\ _get\ _product($value);
$\ _attributes = $\ _child - > get\ _variation\ _attributes();
foreach($\ _attributes as $index => $attr) {
if ('1 pack' == $attr) {
update_post_meta($value, '_stock_status', 'outofstock');
update_post_meta($value, '_manage_stock', 'no');
}
}
}
Спасибо.