Installing the plugin

To upload and install the plugin, go to Plugins > Add New > Upload Plugin and upload the product-extras-for-woocommerce.zip file. Activate the plugin (remember that you will need to have WooCommerce activated as well).

Enter your plugin license

Go to WooCommerce > Settings > Product Extras to enter your license key. This will ensure that you receive automatic updates.

Adding fields to products

Create a new product, or edit an existing one. In the Product Data table, you will see a new ‘Product Extras’ tab:

Add new group

Click the ‘Add Group’ button to add a new group. A group is just a collection of associated fields – for instance, if your users are submitting images, you might have a group that consists of an upload field and a text field for the image title.

Enter a Group title, if required. If you enter a title, it will appear as a heading for the group.

Group requirement setting

There are two requirement options for a group:

  • All required fields
    Choose this to ensure that all fields marked as ‘required’ in the group will need to be completed for the product to be added to the cart
  • All required fields if first field complete
    Choose this to ensure that all fields marked as ‘required’ in the group will need to be completed – but only if the first field in the group is not empty. Typically, you might use this setting if you have more than one group within the product – for example, if you are inviting artists to submit more than one piece of artwork but only the first piece is compulsory.

Add Field

Click ‘Add Field’ to add a field. You can enter an optional label, define the field type, and specify whether the field is required.

Depending on the field type, you may have some other parameters you can enter, such as default values and a description.

Product extras tab and panel

Ensure that the product has a price assigned.

Field types

All fields have the following parameters:

  • Field Label – the label for the field
  • Field Type – select which field type you want to use
  • Price – the amount that will be added to the product price if the option is selected
  • Required – check this if the field must have a value
  • Default – enter a default value here
  • Description – enter an optional description for the field

Fields are listed below along with any additional parameters specific to that field:

  • Checkbox
  • Date
    Min date today – select this to ensure the customer can’t select a date in the past
    Min date – select a minimum date
    Max date – select a max date
  • Name Your Price
    Min value – the minimum value that can be entered
    Max value – the maximum value that can be entered
  • Number
  • Min value – the minimum value that can be entered
    Max value – the maximum value that can be entered
    Multiply price – select this to multiply the price by the number entered when calculating price
  • Radio Group
    Add Option – select this to add a new radio button option
  • Select
    Add Option – select this to add a new option
  • Text
    Min chars – the minimum number of characters that can be entered in this field
    Max chars – the maximum number of characters that can be entered in this field
    Price per character – select this to charge per character entered
  • Textarea
    Min chars – the minimum number of characters that can be entered in this field
    Max chars – the maximum number of characters that can be entered in this field
    Price per character – select this to charge per character entered
  • Upload

Global Extras

You can set extra groups and fields at a global level. Go to Product Extras > Global Extras.

Create a new group and add product fields as above for individual products. You can define rules for where the group is displayed, including:

  • Display on all products
  • Display for a list of specified products
  • Display if the product belongs to a list of specified categories

Conditions

You can add conditions to fields to determine when they are displayed. For instance, you can specify a condition that a field will only be displayed if another field is checked:

You can set multiple conditions and specify whether they all need to be true or only one needs to be true.

Viewing Product Extras

You can view all product extras by clicking the Product Extras menu item in your dashboard. All submissions contain meta data linking them to the user and order number, as well as itemizing each submitted field.

Exporting Product Extras

To export your extras, go to Product Extras > Export. This will generate a CSV file which can be opened in most spreadsheet applications.

Overriding Templates

You can use your own version of the field templates by duplicating files from the plugins template/frontend folder and creating your own product-extras folder in your theme or child theme. The plugin will look for any templates in theme folders before using its default templates.

Filters

Filter file types

If you’re using the file upload field type, you can change the permitted file types by using a filter. Please remember that allowing users to upload files to your server carries a security risk, so please use this feature with caution.

function my_prefix_filter_pewc_file_types( $filetypes ) {
$filetypes = array( 'jpg', 'png' );
return $filetypes;
}
add_filter( 'pewc_protected_directory_allowed_filetypes', 'my_prefix_filter_pewc_file_types' );

Just add the above code and include the file types you wish to allow.

Note that the code above works for file types that are natively supported by WordPress. If you want to upload files types that aren’t already supported by WordPress, you can filter upload_mimes:

function my_prefix_upload_mimes( $mimes ) {
// Add PhotoShop PSD files to list of permitted WordPress mime types
$mimes['psd'] = "application/x-photoshop";
return $mimes;
}
add_filter( 'upload_mimes', 'my_prefix_upload_mimes' );

Filter prices for extras in the cart

If you just want to add the prices for extra items in the cart, just target the pewc-cart-item-price class in CSS. However, you can also filter the price using:

$price = apply_filters( 'pewc_filter_cart_item_price', $price, $item );

Filter field classes

You can filter the class applied to each product extra field, just use the pewc_filter_single_product_classes filter:

function prefix_filter_single_product_classes( $classes, $item ) {
$classes[] = 'my-new-class';
return $classes;
}
add_filter( 'pewc_filter_single_product_classes', 'prefix_filter_single_product_classes', 10, 2 );

The filter also passes the $item object so you can do conditional stuff based on the item.