A
A
anton99992020-04-23 18:49:56
WooCommerce
anton9999, 2020-04-23 18:49:56

How to display an additional field in the product frontend?

Hello,
I can't find a solution. reviewed many plugins and php codes.
I want to create an additional field in the product backend. 5ea1b7c9f3be1797647709.jpeg
and display all this in the line Price2: 37.5 euros in the product card and that it be with the ccs class. no bindings to the base price is needed. no recalculations are needed. and so that it is displayed without being tied to the display of the basket.
5ea1b809a8796659838893.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
anton9999, 2020-04-23
@anton9999

add_action( 'woocommerce_product_options_general_product_data', 'art_woo_add_custom_fields' );
function art_woo_add_custom_fields() {
  global $product, $post;
  echo '<div class="options_group">';// Группировка полей 
  // текстовое поле
woocommerce_wp_text_input( array(
   'id'                => '_text_field',
   'label'             => __( 'Текстовое поле', 'woocommerce' ),
   'placeholder'       => 'Текстовое поле',
   'desc_tip'          => 'true',
   'custom_attributes' => array( 'required' => 'required' ),
   'description'       => __( 'Введите здесь значение поля', 'woocommerce' ),
) );
  echo '</div>';
}
add_action( 'woocommerce_process_product_meta', 'art_woo_custom_fields_save', 10 );
function art_woo_custom_fields_save( $post_id ) {
   // Сохранение текстового поля
   $woocommerce_text_field = $_POST['_text_field'];
   if ( !empty($woocommerce_text_field) ) {
   update_post_meta( $post_id, '_text_field', esc_attr( $woocommerce_text_field ) );
}
}
add_action( 'woocommerce_product_meta_start', 'art_get_text_field_before_add_card' );
function art_get_text_field_before_add_card() {
  global $post;
echo get_post_meta( $post->ID, '_text_field', true );
}

this code displays an additional field mine but in the general class class="product_meta". how to wrap in a separate class?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question