• Can anyone recommend a plug-in (paid or free) that will allow me to create a custom field for my WC products? I am not looking for product “options” where the customer selects from options like size or color. Rather, I just want a few more fields that are set up for each product. I sell sheet music and would like to have the composer in a separate field rather than just text in the product name or description.

    In addition to being able to enter this custom data per product, I’d also like to display the custom field on the product page.

    This seems so straightforward and also seems like something many shops would need to do depending on what they sell. I am surprised that I’m having such difficulty finding a plug-in that will do this.

    Apologies if this sort of query is not appropriate for this forum. I wasn’t sure where else to look beyond the Google searching I’ve already done.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Hi

    I think you don’t need plugin for that, few custom code help you to achive.

    Here is the complete code of custom input fields that you must paste in the functions.php(active theme)

    // Display Fields
    add_action('woocommerce_product_options_general_product_data', 'woocommerce_product_custom_fields');
    // Save Fields
    add_action('woocommerce_process_product_meta', 'woocommerce_product_custom_fields_save');
    function woocommerce_product_custom_fields()
    {
        global $woocommerce, $post;
        echo '<div class="product_custom_field">';
        // Custom Product Text Field
        woocommerce_wp_text_input(
            array(
                'id' => '_custom_product_text_field',
                'placeholder' => 'Custom Product Text Field',
                'label' => __('Custom Product Text Field', 'woocommerce'),
                'desc_tip' => 'true'
            )
        );
        //Custom Product Number Field
        woocommerce_wp_text_input(
            array(
                'id' => '_custom_product_number_field',
                'placeholder' => 'Custom Product Number Field',
                'label' => __('Custom Product Number Field', 'woocommerce'),
                'type' => 'number',
                'custom_attributes' => array(
                    'step' => 'any',
                    'min' => '0'
                )
            )
        );
        //Custom Product  Textarea
        woocommerce_wp_textarea_input(
            array(
                'id' => '_custom_product_textarea',
                'placeholder' => 'Custom Product Textarea',
                'label' => __('Custom Product Textarea', 'woocommerce')
            )
        );
        echo '</div>';
    
    }

    Saving Data in the Database

    function woocommerce_product_custom_fields_save($post_id)
    {
        // Custom Product Text Field
        $woocommerce_custom_product_text_field = $_POST['_custom_product_text_field'];
        if (!empty($woocommerce_custom_product_text_field))
            update_post_meta($post_id, '_custom_product_text_field', esc_attr($woocommerce_custom_product_text_field));
    // Custom Product Number Field
        $woocommerce_custom_product_number_field = $_POST['_custom_product_number_field'];
        if (!empty($woocommerce_custom_product_number_field))
            update_post_meta($post_id, '_custom_product_number_field', esc_attr($woocommerce_custom_product_number_field));
    // Custom Product Textarea Field
        $woocommerce_custom_procut_textarea = $_POST['_custom_product_textarea'];
        if (!empty($woocommerce_custom_procut_textarea))
            update_post_meta($post_id, '_custom_product_textarea', esc_html($woocommerce_custom_procut_textarea));
    
    }

    To get those values, I will use the popular get_post_meta() function

    function woocommerce_custom_fields_display()
    {
      global $post;
      
    // Display the value of custom product text field
        echo get_post_meta($post->ID, '_custom_product_text_field', true);
    // Display the value of custom product number field
        echo get_post_meta(get_the_ID(), '_custom_product_number_field', true);
    // Display the value of custom product text area
        echo get_post_meta(get_the_ID(), '_custom_product_textarea', true);
    }
     
    add_action('woocommerce_before_add_to_cart_button', 'woocommerce_custom_fields_display');

    You must have to add some css/style to show those fields.

    Note: You must need to change title keys as per your need

    Let me know if you need more help.

    Thanks
    Ahir

    Thread Starter earmsby

    (@earmsby)

    Thanks, I will give that a try.

    Hi @earmsby

    Thanks for reaching out!

    In addition to what was proposed above, you could also check the premium plugin, Custom Fields for WooCommerce that simultaneously add custom fields to the Registration, My Account, and Checkout pages. Select from a range of 19 different field types.

    If you want to try our products, please note we have a 30-day refund policy.

    If the product doesn’t work the way you need it or you think another product would work better, we are more than happy to offer a full refund. You can read more about our refund policy on our website here.

    Hope this helps!

    Thread Starter earmsby

    (@earmsby)

    According to your plug-in’s description it only allows “Add custom fields to Registration form and Checkout page”

    I am not looking to add fields to either of these areas but to the product page.

    Since I’ve not had good success with paying for something and then hoping for a refund when it does do what I need, I think I’ll pass on this solution.

    Hi @earmsby

    I am not looking to add fields to either of these areas but to the product page.

    I totally understand that.

    I did some research and found these articles could be a good starting point:

    How to Add Custom Product Fields in WooCommerce
    How to Add Custom Fields to WooCommerce Product Pages
    How to display custom fields on the WooCommerce product page
    Add custom fields to WooCommerce Products using ACF

    Hope this helps!

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Plug-in for custom data field’ is closed to new replies.