In WooCommerce possiamo aggiornare la quantità di prodotti presenti in magazzino.
La soluzione è la seguente:
<?php
function my_wc_update_stock_qty( $product_id, $qty ) {
if( !is_numeric( $qty ) || !filter_var( intval( $qty ), FILTER_VALIDATE_INT ) ) {
return;
}
if( !is_numeric( $product_id ) || !filter_var( intval( $product_id ), FILTER_VALIDATE_INT ) ) {
return;
}
update_post_meta( intval( $product_id ), '_stock', intval( $qty ) );
}