This topic is: not resolved
-
Hello,
I have set up a custom field for variable products, this is the code in my functions.php, it works great I can add, save and delete the EAN.
// Add Variation Meta Field add_action( 'woocommerce_product_after_variable_attributes', 'variation_settings_fields', 10, 3 ); // Save Variation Settings add_action( 'woocommerce_save_product_variation', 'save_variation_settings_fields', 10, 2 ); // Create New Fields for Variations function variation_settings_fields( $loop, $variation_data, $variation ) { // EAN Text Field woocommerce_wp_text_input( array( 'id' => 'EAN[' . $variation->ID . ']', 'label' => __( 'EAN', 'woocommerce' ), 'placeholder' => 'Pls enter EAN if available', 'desc_tip' => 'true', 'description' => __( 'Enter the EAN Number (UPC,EAN)', 'woocommerce' ), 'value' => get_post_meta( $variation->ID, 'EAN', true ) ) ); } // Save new fields for variations function save_variation_settings_fields( $post_id ) { $ean_post = $_POST['EAN'][ $post_id ]; // save the EAN if(isset($ean_post)){ update_post_meta($post_id,'EAN', esc_attr($ean_post)); } // remove if EAN meta is empty $ean_data = get_post_meta($post_id,'EAN', true); if (empty($ean_data)){ delete_post_meta($post_id,'EAN', ''); } }
How can I display the EAN on the product page ?