I have a product with a list of variations, as an example one of the variations is "36" (ID: 17393). I want to set a new price and a new quantity of this variation of the product (with external information).
For now, I have this code, but I have certain functions that I do not know.
<?php
if ( $product->is_type( 'variable' ) ) {
$dataCSV = "36,2.0" , "37,3.0" , "39,4.0"; //example of external info
//$dataCSV have for each "talla" the quantity
$misAtributos = $product->get_attribute('Tallas');
//$misAtributos = 35 | 36 | 37 | 38 | 39 | 40
$AllTallas= explode(" | ", $misAtributos);
foreach ($AllTallas as $key => $talla) {
foreach ($dataCSV as $key => $Qnty) {
//first element [36, 2.0]
//$Qnty[0] = 36
//$Qnty[1] = 2.0
if($talla = $Qnty[0]){
//Update stock of and price.
}
}
echo '<br>'.(float)$value;
}
}
?>
- How to get the ID of the product (17393) instead of the variation name (36)?
- How to set the new price and new quantity for this variation of the product?