Add a custom attribute for a product

In this tutorial we will add a product specific custom attribute. These are not attributes that will be filterable via the WooCommerce Layered Nav. These attributes are stored specifically for a product.

In this article

Here's an example of a custom attribute for a product.

A custom product attribute

Add custom product attribute

Here's how to add the promo field as a custom attribute for a product.


Identify the product field

First we need to see if our products have a promo field. Here's a product that does have a promo field.

The "promo" field

Create a custom plugin

If you haven't done so already, create a custom plugin.


Add custom code

Add the following code to your custom plugin file.


Add/Update product sets

Now, after your Product Set imports its products, a " promo" attribute will be added for each product that has a promo field. The label will display "Special Promotion".

Prevent attributes from being overwritten during update

To prevent your custom attributes from being overwritten during a Product Set update, you'll need to use the code below instead of the code above.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us