Answer the question
In order to leave comments, you need to log in
How to display custom attributes in the product tab to other attributes?
I brought the fields to the admin panel (code below), now I want to add them to the rest of the attributes
add_filter( 'woocommerce_product_data_tabs', 'add_my_custom_product_data_tab' );
function add_my_custom_product_data_tab( $product_data_tabs ) {
$product_data_tabs['my-custom-tab'] = array(
'label' => __( 'Доп.атрибуты', 'my_text_domain' ),
'target' => 'my_custom_product_data',
);
return $product_data_tabs;
}
add_action( 'woocommerce_product_data_panels', 'add_my_custom_product_data_field' );
function add_my_custom_product_data_field() {
global $woocommerce, $post;
?>
<div id="my_custom_product_data" class="panel woocommerce_options_panel">
<?php
woocommerce_wp_textarea_input(
array(
'id' => 'giftwrap_cost1',
'label' => __( 'Текст', 'tpwcp' ),
'desc_tip' => __( 'Введите текст', 'tpwcp' )
)
);
woocommerce_wp_select(
array(
'id' => 'giftwrap_cost2',
'label' => __( 'Упаковка', 'tpwcp' ),
'options' => array(
'value1' => __( 'Мешок', 'textdomain' ),
'value2' => __( 'Text 2', 'textdomain' )
)
)
);
?>
</div>
<?php
}
add_action( 'woocommerce_process_product_meta', 'wc_product_custom_fields_save' );
function wc_product_custom_fields_save($post_id) {
$wc_custom_product_number_field1 = $_POST['giftwrap_cost1'];
if (!empty($wc_custom_product_number_field1)){
update_post_meta($post_id, 'giftwrap_cost1', esc_attr($wc_custom_product_number_field1));}
$wc_custom_product_number_field2 = $_POST['giftwrap_cost2'];
if (!empty($wc_custom_product_number_field2)){
update_post_meta($post_id, '_product_attributes', esc_attr($wc_custom_product_number_field2));}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question