Answer the question
In order to leave comments, you need to log in
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.
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.
Answer the question
In order to leave comments, you need to log in
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 );
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question