Ok, I’ve managed to solve this. This is how i finally created variations custom field:
add_action( 'woocommerce_product_after_variable_attributes', 'variation_settings_fields', 10, 3 );
add_action( 'woocommerce_save_product_variation', 'save_variation_settings_fields', 10, 2 );
function variation_settings_fields( $loop, $variation_data, $variation ) {
woocommerce_wp_text_input(
array(
'id' => 'price_1_50[' . $variation->ID . ']',
'class' => 'price_1_50',
'type' => 'text',
'label' => __( 'Price | Product amount: 1-49', 'woocommerce' ),
'placeholder' => '',
'desc_tip' => 'true',
'description' => __( 'Enter price for product amount 1-49 (if available)', 'woocommerce' ),
'value' => get_post_meta( $variation->ID, 'price_1_50', true )
)
);
}
function save_variation_settings_fields( $post_id ) {
$text_field = $_POST['_price_1_50'][ $post_id ];
if( ! empty( $text_field ) ) {
update_post_meta( $post_id, 'price_1_50', esc_attr( $text_field ) );
}
}
And this is how i got the desired result in frontend (based on: https://stackoverflow.com/questions/47646939/how-to-get-woocommerce-variation-id)
$args = array(
'post_type' => 'product_variation',
'post_status' => array( 'private', 'publish' ),
'numberposts' => -1,
'orderby' => 'menu_order',
'order' => 'asc',
'post_parent' => get_the_ID() // get parent post-ID
);
$variations = get_posts( $args );
foreach ( $variations as $variation ) {
$variation_ID = $variation->ID;
$product_variation = new WC_Product_Variation( $variation_ID );
get_post_meta( $variation_ID , 'price_1_50', true );
}