我有一个带有变体列表的产品,例如其中一个变体是“36”(ID:17393)。我想为产品的这种变化设置一个新价格和一个新数量(带有外部信息)。
现在,我有这段代码,但我有一些我不知道的功能。
<?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;
}
}
?>
- 如何获取产品的 ID (17393) 而不是变体名称 (36)?
- 如何为产品的这种变化设置新的价格和新的数量?