Nossa equipe de especialistas está à disposição para responder suas dúvidas e fornecer informações detalhadas sobre nossas tecnologias e modelos de entrega. Entre em contato conosco com a certeza de que receberá um atendimento profissional, ágil e direcionado. Confie na expertise da Wishbox e fortaleça sua jornada na manufatura aditiva com quem entende do assunto.
plugins premium WordPress
add_filter( 'woocommerce_product_get_default_attributes', 'auto_define_default_variation_attributes', 10, 2 );
function auto_define_default_variation_attributes( $default_attributes, $product ){
$variation_attributes = $product->get_variation_attributes();// Loop through available variations
foreach( $product->get_available_variations('objects') as $variation ) {
// Target purchasable in stock variation
if ( $variation->is_purchasable() && $variation->is_in_stock() ) {
// Loop through attributes for the current variation
foreach( $variation->get_attributes() as $attribute => $value ) {
if ( ! empty($value) ) {
$default_attributes[$attribute] = $value;
} else {
// If there is no defined value, set it
foreach( $variation_attributes as $variation_attribute => $values ) {
if ( $attribute === sanitize_title($variation_attribute) ) {
$default_attributes[$attribute] = current($values);
break;
}
}
}
}
break; // Stop the loop
}
}
return $default_attributes; // Always return the values in a filter hook
}