In WooCommerce, I have added a product custom field (a product note) and it is displayed successfully in single product pages, under add to cart button.
How can I display that custom field value on admin order pages?
This is my field code:
add_action('woocommerce_after_add_to_cart_button', 'custom_product_note', 5 );
function custom_product_note() {
global $product;
if ( $product->is_type( 'variable' ) ) {
echo '<br><div style="margin-top:20px;">';
woocommerce_form_field('product_note', array(
'type' => 'textarea',
'class' => array( 'my-field-class form-row-wide') ,
'label' => __('Product Note - You can add up to 15 characters.') ,
'maxlength' => ('15'),
'placeholder' => __('Add a product note, please.') ,
'required' => true,
) , '');
echo '</div>';
}
}
2
Answers
thank you for answer. It was worked.
First, you need the field value when adding to cart a product:
Then you need to save this custom product note in the order data (specifically in the order item as custom metadata):
Code goes in functions.php file of your child theme (or in a plugin). Tested and works