Answer the question
In order to leave comments, you need to log in
Why is woocommerce custom field value not showing?
Added custom field for woocommerce. But I can't display it on the site. An error is displayed.
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' => __( 'ISBN', 'woocommerce' ),
'placeholder' => 'Текстовое поле',
'desc_tip' => 'true',
'custom_attributes' => array( 'required' => 'required' ),
'description' => __( 'ISBN — это международный номер бумажной или электронной книги.', '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 ) );
// $product->save();
}
}
add_action('woocommerce_template_single_price',function(){
$product = wc_get_product();
echo get_post_meta($product->get_id(),key '_text_field', single true);
},15)
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