Support

Account

Home Forums ACF PRO Set product category (WooCommerce) from an acf select field within acf form

Helping

Set product category (WooCommerce) from an acf select field within acf form

  • Hi,

    First of all sorry for my poor English.

    Actual configuration:

    – I use ACF to create products via acf form. The form has a first ‘Brand’ field (selector) and, according to the choice made, a ‘Models’ field (selector) containing the models corresponding to the brand is displayed.
    – The ‘Brand’ field contains a list of 200 brands, and there are as many ‘Models’ conditional fields as there are brands
    – In parallel, product categories (WooCommerce) have been created which include the brands (200). These categories are child categories of the parent category ‘Motorcycles’

    My problem:

    When submitting the form, I would like the product created to be included in the category corresponding to the choice made in the ‘Brand’ field and unregistered from uncategorized category.

    I don’t want to use the Taxonomy field of ACF because with conditional logic we cannot use ‘Value is equal to’. In addition, I do not want the parent category ‘Motorcycles’ to be visible in the ‘Brand’ selector.

    Hoping that my explanation is clear.

    Thanks so much for helping me

  • You need to create an acf/save_post filter https://www.advancedcustomfields.com/resources/acf-save_post/

    In this filter you need to get the value from the field and then find the correct “category”. I don’t know what this field contains but you should be able to get the term in some way. Then when you have that you use https://developer.wordpress.org/reference/functions/wp_set_post_terms/ to place the post in the category.

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

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.