1 回答

TA貢獻(xiàn)1810條經(jīng)驗(yàn) 獲得超4個(gè)贊
嘗試這個(gè)
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 關(guān)注
- 220 瀏覽
添加回答
舉報(bào)