ID, $customFieldName, true); $args = array( 'label' => $customFieldLabel, 'placeholder' => __('Enter value', 'a4-barcode-generator'), 'id' => $customFieldName, 'desc_tip' => true, 'description' => __('This field created by "Barcode Label Printing 4 for WooCommerce - free" plugin, you can rename this field or disable it in the plugin\'s settings.', 'a4-barcode-generator'), 'value' => $value ); \woocommerce_wp_text_input($args); }); add_action('woocommerce_process_product_meta', function ($postId) use ($customFieldName) { $usbsBarcodeField = isset($_POST[$customFieldName]) ? sanitize_text_field($_POST[$customFieldName]) : ''; update_post_meta($postId, $customFieldName, $usbsBarcodeField); }); add_action('woocommerce_variation_options_pricing', function ($loop, $variation_data, $variation) use ($customFieldLabel, $customFieldName) { $value = get_post_meta($variation->ID, $customFieldName, true); $args = array( 'class' => 'short', 'label' => $customFieldLabel, 'placeholder' => __('Enter value', 'a4-barcode-generator'), 'id' => $customFieldName . '_v[' . $loop . ']', 'desc_tip' => true, 'description' => __('This field created by "Barcode Label Printing 4 for WooCommerce - free" plugin, you can rename this field or disable it in the plugin\'s settings.', 'a4-barcode-generator'), 'value' => $value, 'wrapper_class' => 'form-row form-row-full' ); \woocommerce_wp_text_input($args); }, 10, 3); add_action('woocommerce_save_product_variation', function ($variationId, $loop) use ($customFieldName) { $value = isset($_POST[$customFieldName . '_v']) && isset($_POST[$customFieldName . '_v'][$loop]) ? sanitize_text_field($_POST[$customFieldName . '_v'][$loop]) : ""; update_post_meta($variationId, $customFieldName, $value); }, 15, 2); } }