function my_template_loop_product_title(){
global $product;
echo '<span itemprop="name" class="product_title entry-title">';
$subheadingvalues = get_the_terms( $product->id, 'pa_avtory');
if ($subheadingvalues){
echo '<b>Авторы:<b><br>';
foreach ($subheadingvalues as $subheadingvalue) {
echo $subheadingvalue->name.'<br>';
}
}
echo '</span>';
}
add_action( 'woocommerce_shop_loop_item_title', 'my_template_loop_product_title', 10 );
add_action( 'woocommerce_product_after_variable_attributes', 'cr_variable_fields', 10, 3 );
add_action( 'woocommerce_product_after_variable_attributes_js', 'cr_variable_fields_js' );
add_action( 'woocommerce_save_product_variation', 'save_cr_variable_fields', 10, 2 );
add_action( 'woocommerce_process_product_meta_variable-subscription' , 'save_variable_fields' , 10 , 1 );
/**
* Создает новое поле
*/
function cr_variable_fields( $loop, $variation_data, $variation ) {
?>
<tr>
<td>
<?php
woocommerce_wp_text_input(
array(
'id' => '_text_field['.$loop.']',
'label' => __( 'Мое текстовое поле', 'woocommerce' ),
'placeholder' => __( 'Подсказка', 'woocommerce' ),
'desc_tip' => 'true',
'description' => __( 'Введите ваше значение.', 'woocommerce' ),
'value' => get_post_meta( $variation->ID, '_text_field', true )
)
);
?>
</td>
</tr>
<?php
}
/**
* Создает поле нового варианта
*/
function cr_variable_fields_js() {
?>
<tr>
<td>
<?php
woocommerce_wp_text_input(
array(
'id' => '_text_field[ + loop + ]',
'label' => __( 'Мое текстовое поле', 'woocommerce' ),
'placeholder' => __( 'Подсказка', 'woocommerce' ),
'desc_tip' => 'true',
'description' => __( 'Введите ваше значение.', 'woocommerce' ),
'value' => ''
)
);
?>
</td>
</tr>
<?php
}
/**
* Сохраняет поле
*/
function save_cr_variable_fields( $post_id ) {
if (isset( $_POST['variable_sku'] ) ) :
$variable_sku = $_POST['variable_sku'];
$variable_post_id = $_POST['variable_post_id'];
$_text_field = $_POST['_text_field'];
for ( $i = 0; $i < sizeof( $variable_sku ); $i++ ) :
$variation_id = (int) $variable_post_id[$i];
if ( isset( $_text_field[$i] ) ) {
update_post_meta( $variation_id, '_text_field', stripslashes( $_text_field[$i] ) );
}
endfor;
endif;
}