Где я ошибаюсь?// Display Fields
add_action( 'woocommerce_product_options_general_product_data', 'woo_add_custom_general_fields' );
// Save Fields
add_action( 'woocommerce_process_product_meta', 'woo_add_custom_general_fields_save' );
function woo_add_custom_general_fields() {
global $woocommerce, $post;
echo '';
// Text Field #1
woocommerce_wp_text_input(
array(
'id' => '_text_field_1',
'label' => __( 'Campo aggiuntivo #1', 'woocommerce' ),
)
);
// Text Field #2
woocommerce_wp_text_input(
array(
'id' => '_text_field_2',
'label' => __( 'Campo aggiuntivo #2', 'woocommerce' ),
)
);
// Text Field #3
woocommerce_wp_text_input(
array(
'id' => '_text_field_3',
'label' => __( 'Campo aggiuntivo #3', 'woocommerce' ),
)
);
echo '';
}
///
function woocommerce_product_custom_fields_save($post_id){
$woocommerce_custom_product_text_field_1 = $_POST['_text_field_1'];
if (!empty($woocommerce_custom_product_text_field))
update_post_meta($post_id, '_custom_product_text_field_1', esc_attr($woocommerce_custom_product_text_field_1));
$woocommerce_custom_product_text_field_2 = $_POST['_text_field_2'];
if (!empty($woocommerce_custom_product_number_field))
update_post_meta($post_id, '_custom_product_text_field_2', esc_attr($woocommerce_custom_product_text_field_2));
$woocommerce_custom_product_text_field_3 = $_POST['_text_field_3'];
if (!empty($woocommerce_custom_procut_textarea))
update_post_meta($post_id, '_custom_product_text_field_3', esc_html($woocommerce_custom_product_text_field_3));
}
///
add_action( 'woocommerce_before_single_product', 'custom_action', 15 );
function custom_action() {
// Display Custom Field Value
echo get_post_meta($post->ID, '_custom_product_text_field_1', true);
echo get_post_meta($post->ID, '_custom_product_text_field_2', true);
echo get_post_meta($post->ID, '_custom_product_text_field_3', true);
}
Подробнее здесь: https://stackoverflow.com/questions/521 ... erce-produ
Мобильная версия