I have the product id:- $posts
. Now i have to change product variable variation stock to outofstock using code.I have bellow snippet code but it's not updating the variation stock of the product. so any one tell me how to do this.
$children = get_posts( array(
'post_parent' => $posts,
'posts_per_page'=> -1,
'post_type' => 'product_variation',
'fields' => 'ids',
'post_status' => 'publish'
) );
$out_of_stock_staus = 'outofstock';
foreach ( $children as $child_id ) {
echo $child_idss= $child_id->ID;
echo $child_stock_status = get_post_meta( $child_id, '_stock_status', true );
// $child_stock_status = $child_stock_status ? $child_stock_status : 'instock';
//wc_update_product_stock_status( $product_id, $stock_statusss );
update_post_meta( $child_id, '_stock_status', wc_clean( $out_of_stock_staus ) );
}