Wordpress WooCommerce Text Attribute

I am using the WooCommerce plugin in Wordpress. In this plugin, I need to add text input for each product, where in the clients you can fill in additional information about the product.

The problem I am facing is that whenever I add a text attribute, it changes in the selection box. Please suggest some solution. Thanks!

+4
source share
1 answer

Do you mean that your clients should have this input text field in the interface?

If it's just a backend, you can add this to your .php functions:

if (is_admin()){ // Add the Meta Box function add_textfield() { add_meta_box( 'textfield', // $id 'Custom textfield', // $title 'show_textfield_backend', // $callback 'product', // $page 'normal', // $context 'high' // $priority ); } add_action('add_meta_boxes', 'add_textfield'); // The Callback function show_textfield_backend() { global $post; global $wpdb; $meta = get_post_meta($post->ID, 'textfield', true); // Use nonce for verification echo '<input type="hidden" name="textfield_nonce" value="'.wp_create_nonce(basename(__FILE__)).'" />'; _e('Custom textfield: '); echo '<input type="text" placeholder="text" id="textfield" class="textfield" name="textfield" ', $meta ? " value='$meta'" : "",' />'; } // Save the Data function save_textfield($post_id) { global $wpdb; // verify nonce if (!wp_verify_nonce($_POST['textfield_nonce'], basename(__FILE__))) return $post_id; // check autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id; // check permissions if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) return $post_id; } elseif (!current_user_can('edit_post', $post_id)) { return $post_id; } if ( !wp_is_post_revision( $post_id ) ) { $textfield = $_POST['textfield']; update_post_meta($post_id, 'textfield', $textfield); } } add_action('save_post', 'save_textfield'); } 
-2
source

All Articles