我需要在产品缺货时允许订购,并读取库存数量。如果我设置了allow backorder[允许延期交货],则以下代码的[最大数量]始终为0且不起作用:
if ($product->product_type == \'variable\') {
foreach ($product->get_available_variations() as $key) {
$attr_string = \'\';
foreach ( $key[\'attributes\'] as $attr_name => $attr_value) {
$attr_string[] = $attr_value;
}
if ( $key[\'max_qty\'] > 0 ) { echo \'<style> body span.swatch.swatch-label.swatch-\' . implode(\', \', $attr_string) . \' {opacity:1!important; background: #484848!important; color: #fff!important;}</style>\'; } else { }
}
}