Custom meta key not working
-
Hi, so I have tried desperately to create a custom meta field to get exported with this plugin but without any luck. I have created a custom field in the product general section, where I can input an image file name. The snippet code is below
// Display Fields add_action('woocommerce_product_options_general_product_data', 'woocommerce_product_custom_fields'); // Save Fields add_action('woocommerce_process_product_meta', 'woocommerce_product_custom_fields_save'); function woocommerce_product_custom_fields() { global $woocommerce, $post; echo '<div class="product_custom_field">'; // Field function woocommerce_wp_text_input( array( 'id' => '_custom_image_name', 'placeholder' => 'Image file name (ex. name.png)', 'label' => __('Image file', 'woocommerce'), 'desc_tip' => 'true' ) ); echo '</div>'; } function woocommerce_product_custom_fields_save($post_id) { // Save function $woocommerce_custom_image_name = $_POST['_custom_image_name']; if (!empty($woocommerce_custom_image_name)) update_post_meta($post_id, '_custom_image_name', esc_attr($woocommerce_custom_image_name)); }
As the code above provides a meta key with name _custom_image_name, once I populate it in product page, I add the meta field and do a test order. In the plugin, I add the meta key and do a test export and the result provides the meta key column empty. Could anyone please help with this? I tried getting it to work in the last 3 weeks without any luck.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘Custom meta key not working’ is closed to new replies.