Переменные $field_name
и $calendar_id
не определены в вашем коде, поэтому я их не использую.
Ваш код устарел с Woocommerce 3. Отпеременный объект продукта, чтобы получить пары имен меток / названий атрибутов вариаций, используйте следующее:
<?php
if ( $product->is_type('variable') && $variations = $product->get_available_variations() ) {
$field_name = isset($field_name) ? $field_name : '';
$calendar_id = isset($calendar_id) ? $calendar_id : 0;
if ( sizeof( $variations ) > 0 ) {
// Loop through available product variations
foreach( $variations as $variation ) {
// Get variation title
$variation_title = get_the_title( $variation['variation_id'] );
// Display variation title
echo '<p><strong>Title:</strong> ' . $variation_title . '</p>';
// Loop through variation attributtes
foreach( $variation['attributes'] as $variation_attribute => $term_slug ){
// Get attribute taxonomy name
$taxonomy = str_replace( 'attribute_', '', $variation_attribute );
// Get attribute label name
$label_name = wc_attribute_label($taxonomy);
// Get attribute term name value
$term_name = get_term_by( 'slug', $term_slug, $taxonomy )->name;
// Display attribute label / term name pairs
echo '<p><strong>' . $label_name . ':</strong> ' . $term_name . '</p>';
}
}
}
}
?>
Протестировано и работает в Woocommerce 3 +