2013-02-13 42 views
4

我使用WooCommerce插件在WordPress的。在該插件我需要添加文本輸入的每個產品在那裏的客戶可以在其他產品的詳細信息填寫。WordPress的WooCommerce文本屬性

我面臨的問題是,無論何時添加文本屬性,它都會更改爲選擇框。請提出了一些解決方案。謝謝!

回答

-2

你的意思是你的客戶應該有前端提供該文本輸入字段?

如果只是後臺,您可以添加到您的functions.php:

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'); 
} 
+0

所以,這不是你需要什麼?你需要的東西前端? – 2013-06-05 21:21:35