Hi,
1. To not show the size button when the product size stock is equal to 0, you have to disable the option "Display out of stock products" in Configuration > Display > Products. Then if you use the value "radio button" for the characteristic display option, the button will not be displayed. If it is not the case, you have to check your overrides which are potentially interacting.
2. To show the badges only if all sizes are sold out I invite you to add the following code at the top of the view "product / show_block_img":
if(isset($this->element->variants)){
$outOfStock = 1;
foreach($this->element->variants as $variant){
if($variant->product_quantity != '0')
$outOfStock = 0;
}
if($outOfStock){
$db = JFactory::getDBO();
$db->setQuery('SELECT * FROM '.hikashop_table('badge').' WHERE badge_id = XX');
$emptyBadge = $db->loadObject();
if(!empty($emptyBadge)){
if(is_null($this->element->badges))
$this->element->badges = array($emptyBadge);
else
$this->element->badges[] = $emptyBadge;
}
}
}
Just replace "XX" by the id of the desired badge, and in the badge settings set the quantity field on "0" and let the quantity of the main product on "unlimited" (-1).