This topic is: not resolved
-
Hello!
I use 2 variation of add custom fields to woocommerce:
1. I use this code in function.php
// Добавляем текстовое поле с выходом блюда - https://www.proy.info/how-to-add-woocommerce-custom-fields/ add_action( 'woocommerce_product_options_general_product_data', 'woocom_custom_field_product_amount' ); function woocom_custom_field_product_amount() { // Create a custom text field // Text Field woocommerce_wp_text_input( array( 'id' => 'product_amount', 'label' => __( 'Количество', 'woocommerce' ), 'placeholder' => '', 'desc_tip' => 'false', // 'description' => __( 'Enter the custom value here.', 'woocommerce' ) ) ); } // Hook to save the data value from the custom fields add_action( 'woocommerce_process_product_meta', 'woocom_save_custom_field_product_amount' ); /** Hook callback function to save custom fields information */ function woocom_save_custom_field_product_amount( $post_id ) { // Save Text Field $text_field = $_POST['product_amount']; if( ! empty( $text_field ) ) { update_post_meta( $post_id, 'product_amount', esc_attr( $text_field ) ); } } // Display Custom Field Value echo get_post_meta( $post->ID, 'product_amount', true );
2. I use plugin “WooCommerce Custom Fields” (https://codecanyon.net/item/woocommerce-custom-fields/11332742?s_rank=5)
In first case (in Function.php) I made a custom field called ‘product_amount’.
In second case (in plugin “WooCommerce Custom Fields”) I made a custom field called ‘serving_size’Then in Elementor I choose “Woo Product Custom_Key” and enter custom key. I tried and “product_amount” and “serving_size” (without quotation marks). And any custom fields are not showing