1 回答
TA贡献1804条经验 获得超3个赞
试试这个
global $product;
$taxonomy = 'pa_sizes'; // The product attribute taxonomy
$sizes_array = []; // Initializing
// Loop through available variation Ids for the variable product
foreach( $product->get_children() as $child_id ) {
$variation = wc_get_product( $child_id ); // Get the WC_Product_Variation object
if( $variation->is_purchasable() && $variation->is_in_stock() ) {
$term_name = $variation->get_attribute( $taxonomy );
$file_list[$term_name] = $term_name;
}
}
/*
* Loop through the array and print all the values
*/
if(is_array($file_list)){
sort ($file_list);
foreach($file_list as $file){
echo '<button class="btn btn-circle btn-lg rounded-circle">' . $file . '</button>';
}
}
else{
echo '<p style="font-size:12px;">No Sizes Available</p>';
}
- 1 回答
- 0 关注
- 128 浏览
添加回答
举报