'Get specific attribute value by varation product id woocommerce

I want to get the attribute value for the variaton id, I tried something but show me the value for 1 month "1 luna".

The 120E price is for 12 months.

enter image description here

The variable that show the period is defined by $perioada

Also the specific attribute is: pa_perioada

The code:

 function produseselectate() {
     global $woocommerce;
    $items = $woocommerce->cart->get_cart();
    $display = '';
 
    
      foreach($items as $item => $values) { 
            $_product =  wc_get_product( $values['data']->get_id()); 
        
            $display .= " <p style='font-size: 1.5em'>".$_product->get_title().'</p>  <br> <p>Cantitate: '.$values['quantity'].'</p><br>'; 
            $price = get_post_meta($values['variation_id'] , '_price', true);
            $display .=  "  <p>Pret unitar: ".$price. "€ </p><br>";
            $perioada = array_shift( wc_get_product_terms( $_product->id, 'pa_perioada', array( 'fields' => 'names' ) ) );
             $display .=  " <p>Perioada: ".$perioada. "</p><br>";
             $subtotal = $price * $values['quantity'];
             $display .=  " <b>Subtotal: ".$subtotal. "</b><br><br><br>";
         
        } 
           $display .= "<p style='font-size: 2em'>Total de plată:" .floatval( preg_replace( '#[^\d.]#', '', $woocommerce->cart->get_cart_total() ) ). "€"; 
     return $display;

}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source