没有变化的产品属性不会显示在商店页面中(&A);产品页面
在产品(Refer blog )
注:产品变体仅用于可变产品。
然后将此代码放入函数中。php
add_action( \'woocommerce_after_shop_loop_item_title\', \'bbloomer_echo_stock_variations_loop\' );
function bbloomer_echo_stock_variations_loop(){
global $product;
if ( $product->get_type() == \'variable\' ) {
foreach ( $product->get_available_variations() as $key ) {
$attr_string = array();
foreach ( $key[\'attributes\'] as $attr_name => $attr_value ) {
$attr_string[] = $attr_value;
$arr_names[] = $attr_name;
}
$attr_color = $arr_names[0];
$attr_size = $arr_names[1];
$strle = \'attribute_pa_\';
$attr_name_a = substr($attr_color, strlen($strle));
$attr_name_a2 = substr($attr_size, strlen($strle));
if ( $key[\'max_qty\'] > 0 ) {
echo \'<div><p>\' .$attr_name_a.\' : \'.$attr_string[0].\' , \'.$attr_name_a2.\' : \'.$attr_string[1].\' , \' . $key[\'max_qty\'] . \' in stock</p></div>\';
} else {
echo \'<div><p>\' .$attr_name_a.\' : \'. $attr_string[0].\',\' .$attr_name_a2.\' : \'.$attr_string[1].\' out of stock</p></div>\';
}
}
}
}
如下图所示: