The question is to write the value in an arbitrary field on a given basis. The attribute is the presence of an attribute with a specific value . I tried it this way (for a variable product), but there’s no point:
function woocommerce_product( $price, $_this) { if ( 'product_variation' === $_this->post_type ) { $data = (object) $_this->get_data(); $parent_id = $data->parent_id; $attribute_name = get_the_terms($product->get_id(), 'pa_razmer'); $n = 6; if ( $attribute_value == '30m') { update_post_meta($product_id, 'custom_field', $n); } } return; } add_filter( 'woocommerce_product_variation_get_price', 'woocommerce_product', 10, 2); Where 'custom_field' is the name of an arbitrary field.
UPDATE
function filter_woocommerce_product_variation_get_p( $price, $_this) { if ( 'product_variation' === $_this->post_type ) { // $data = (object) $_this->get_data(); $parent_id = $data->parent_id; $product_id = 596; $attribute_name = get_the_terms( $product>id, 'pa_razmer'); $n = 6; foreach ( $attribute_name as $value ) { //echo $value->slug; if ( $product_id === $parent_id ) { if ( $value->slug == '30m' ) { update_post_meta($product_id, 'custom_field', $n); } } } } return; } 