Следующее отобразит после выбранной цены изменения (для переменных продуктов) соответствующий тип упаковки, например, например: "€ 39, - для коробки по 300 г" …
add_filter( 'woocommerce_available_variation', 'set_packaging_type_after_variation_price', 10, 3 );
function set_packaging_type_after_variation_price( $data, $product, $variation ) {
$targeted_taxonomy = 'pa_verpackung'; // <== Define here the product attribute taxonomy
// Loop through variation attributes
foreach( $data['attributes'] as $variation_attribute => $term_slug ) {
$attribute_taxonomy = str_replace( 'attribute_', '', $variation_attribute ); // Get product attribute the taxonomy
// For matching variation attribute …
if ( $attribute_taxonomy == $targeted_taxonomy ){
$verpackung = get_term_by( 'slug', $term_slug, $attribute_taxonomy )->name; // Get the term name
$verpackung = ' <span class="verpackung">'. __('für eine '). $verpackung .'</span></span>';
// Set the "packaging" after the selected viariation price
$data['price_html'] = str_replace( '</span></span>', '</span>' . $verpackung, $data['price_html'] );
break; // Stop the loop
}
}
return $data;
}
Код помещается в файл function.php вашей активной дочерней темы (или активной темы).Проверено и работает.