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; } 
  • You have $ attribute_value not defined - KAGG Design
  • yes, really, and how to write in it the list of values? or is the list of values ​​already stored $ attribute_name ? - user271244
  • why not take and see what's in $ attribute_name? - KAGG Design
  • looked upset - bool (false), no arguments are passed for get_the_terms () - user271244
  • I showed you in my answer how to work with attributes: ru.stackoverflow.com/a/735241/220220 - KAGG Design

1 answer 1

It was necessary to add just one line to the code of my previous answer:

 function filter_738363_woocommerce_product_variation_get_price( $price, $_this) { if ( 'product_variation' === $_this->post_type ) { $data = (object) $_this->get_data(); $variation_price = $data->price; $product_id = $data->parent_id; $variation_rrp_price = get_rrp_price( $variation_price, $product_id ); update_post_meta( $product_id, $data->name, $variation_rrp_price ); $price = $variation_rrp_price; } return $price; } add_filter( 'woocommerce_product_variation_get_price', 'filter_738363_woocommerce_product_variation_get_price', 10, 2); 

So now the arbitrary fields of the goods under the name "Variable goods" look like:

enter image description here

Fields underlined are underlined.