nice to greet you.
I’m developing a plugin and apparently it made all the products disappear from its category.
I’m not sure what could have caused the error, since the plugin updates price based on a formula.
I share a snippet of the code.
foreach ($catalogInventory as $valueCatalogInventory) {
if ($valueCatalogInventory->Sku == $valueCatalog->Sku) {
$sku = $valueCatalog->Sku;
$Checkprecio = ( $valueCatalogPrice->Price->UnitPrice == 0 ) ? 0 : $valueCatalogPrice->Price->UnitPrice;
$price = floatval(sanitize_text_field($Checkprecio));
//formula
$product_id = get_id_by_SKU($sku);
$priceBruto = round(($price*$dolar));
if ($priceBruto < 50000) {
$priceVenta = round(($price*$dolar)*1.3333*$comision);
}elseif($priceBruto > 50000 && $priceBruto <= 100000){
$priceVenta = round(($price*$dolar)*1.1905*$comision);
}elseif($priceBruto > 100000 && $priceBruto <= 200000){
$priceVenta = round(($price*$dolar)*1.1494*$comision);
}elseif($priceBruto > 200000 && $priceBruto <= 400000){
$priceVenta = round(($price*$dolar)*1.1236*$comision);
}elseif ($priceBruto > 400000) {
$priceVenta = round(($price*$dolar)*1.1111*$comision);
}
var_dump($product_id);
update_post_meta($product_id, '_regular_price', $priceVenta );
update_post_meta($product_id, '_price', $priceVenta );
}
}
any help would be appreciated.