Support

Account

Home Forums ACF PRO Adding fields to WooCommerce Attributes (not attribute terms)

Solving

Adding fields to WooCommerce Attributes (not attribute terms)

  • I assume this is possible, but probably with more digging into things than I’ve been able to do…

    WooCommerce has a bunch of taxonomies associated with it. One is Attributes, commonly used for things like “Shirt Color”, and then under that attribute would be terms, like “Red”, “Yellow” and “Blue”. Here’s how these are represented in the backend UI:

    Attribute list/add screen

    Something seems a bit odd with the attributes, they have an edit URL like this that does not reference a post_id or anything, and the numbering starts at 1 and increments with each attribute:

    wp-admin/edit.php?post_type=product&page=product_attributes&edit=1

    The terms are simple, which is why I guess it’s easy to add fields there with the normal taxonomy selections in ACF:

    wp-admin/edit-tags.php?taxonomy=pa_altacom-ceramics&post_type=product (list of terms)

    wp-admin/term.php?taxonomy=pa_altacom-ceramics&tag_ID=2804&post_type=product&wp_http_referer=%2Fwp-admin%2Fedit-tags.php%3Ftaxonomy%3Dpa_altacom-ceramics%26post_type%3Dproduct (editing an individual term)

    And you can see here we use ACF to add a field for an image to each term:

    Our addtion to an Attribute Term

    Hope that all makes sense – we want to add a field not at the “term” level (we’ve already done that), but at the attribute level, which seems to be hard because Woo is doing something unique here…

    Technically we could add the field to the terms, but that would mean setting a few fields on a few thousand terms, which would be kind of laborious.

    Any ideas?

  • Did you ever solve this? I was looking for something similar and hope to have found a solution in:

    Adding Custom Post Type UI. Then add a new custom posttype like “Attribute extras”. After that you can add a new group in ACF and add an image and extra description for example. Also you add a Taxonomy field with the field name matching the slug of the Attribute. You do this for each Attribute (in my case about 30).

    Finally when you add a new “Attribute Extra” you use the Title to match the slug of the actual attribute. In front you then make some custom code to display the image instead of the attribute value.

    Still testing this as I want to import all (2000+) Attribute Extra’s. I’ll let you know if it works

  • The page in question is a custom admin sub page that mimics a taxonomy admin page. I haven’t got a clue how this is added or if there is any way to change it. I did a search on the subject and found no information on changing this page. Changing this page would require WC having some type of action hook that runs when showing this page that would allow you to add ACF field groups to the form. It appears that the only source of information on if this can be done would be WC. If you can get information on if/how it is possible to alter this page then I could probably help you to add ACF fields to the page.

    Then the next problem would be where the information is actually stored and how to retrieve it because this page is simply an interface that allows you to add product attributes. From my understanding of this, each “attribute” that is added is a actually a new custom taxonomy and then then list for each of these has sub terms. So the interface is actually letting you create your own custom taxonomies associated with WC. So there really isn’t anywhere that this information is stored or to store any information associated with it. This would be like having information stored that is used on all “categories” or “tags” there is nowhere in WP to store information like this. So even if you could figure out how to alter this page I think that the effort would be wasted.

  • Actually, there is a solution, but I didn’t have enough time to realize it through acf, maybe this will help someone to realize this task.
    And so: on the page of creating/editing taxonomy (attribute), custom form, which has hooks:
    woocommerce_after_edit_attribute_fields – for the attribute edit page.
    woocommerce_after_add_attribute_fields – for the add attribute page.

    I can add a custom input \select \anything through this hook, and then, on the admin_init hook (for example), check $_POST and if my input is there (if my input is there, there will be other inputs from the form), save this value in the database table. You can save it anywhere, but it is more correct to save it in a custom table, and create a link, for example, by the key (slug) of the attribute, for example pa_finish. And as a result, when processing a product or a taxonomy term, we can take the slug of the taxonomy (attribute) and use it in the custom table in the database to get the value that we attached to the form of creating/editing the attribute.
    Thus, I can save primitive data, such as select to specify the type of display attribute (image \ color \ text \ select) and based on this, display the necessary html for a particular attribute.

    John Huebner – I’ve seen a lot of your posts, and I think you can do it).

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.