I've created a custom field for warranty in my products pages, via function.php.
add_action( 'woocommerce_product_options_general_product_data', 'test_custom_fields' );
function test_custom_fields() {
// Print a custom text field
woocommerce_wp_text_input( array(
'id' => '_warranty',
'label' => 'i.e. 15 years',
'description' => '',
'desc_tip' => 'true',
'placeholder' => 'i.e. 15 years'
) );
}
add_action( 'woocommerce_process_product_meta', 'test_save_custom_fields' );
function test_save_custom_fields( $post_id ) {
if ( ! empty( $_POST['_warranty'] ) ) {
update_post_meta( $post_id, '_warranty', esc_attr( $_POST['_warranty'] ) );
}
}
I would like to "duplicate" this custom field with key and value, in an self-generated custom field on the admin order page depending on products in cart/order (without plugin).
So, with this custom field on order page, I will finally be able to display "warranty" in my pdf invoice with WooCommerce PDF Invoice plugin.
Another explanation :
- As admin, I fill _warranty value in "product1" page
- When "product1" is in an order, on the admin order view, I would like to see a custom field containing "_warranty + value" from product1 page.
- So, as admin, I could set
{{_warranty}}
in WooCommerce PDF Invoice plugin to display "Warranty : 15 years"
Many thanks for your help.
I have just tested the following case: show product meta in order items table in Order Details
But this does not give me a custom field, so I couldn't get my {{_warranty}}
value width it.
What I am doing wrong?
How can I achieve this?
Thanks.