【问题标题】:Wordpress WooCommerce text attributeWordpress WooCommerce 文本属性
【发布时间】:2013-02-13 12:32:51
【问题描述】:

我在 Wordpress 中使用 WooCommerce 插件。在该插件中,我需要为每个产品添加文本输入,客户可以在其中填写其他产品详细信息。

我面临的问题是,每当我添加文本属性时,它都会变成一个选择框。请提出一些解决方案。谢谢!

【问题讨论】:

    标签: php wordpress woocommerce


    【解决方案1】:

    您的意思是您的客户应该在前端提供此文本输入字段吗?

    如果只是后端,你可以将它添加到你的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');
    }
    

    【讨论】:

    • 那么,这不是您所需要的吗?你需要前端的东西吗?
    猜你喜欢
    • 2014-08-02
    • 1970-01-01
    • 1970-01-01
    • 2014-06-20
    • 1970-01-01
    • 1970-01-01
    • 2018-01-13
    • 2017-04-07
    • 1970-01-01
    相关资源
    最近更新 更多