Home › Forums › Backend Issues (wp-admin) › Use product category for ACF conditions
Hello.
I’m setting my ACF group conditions, and, for now, i have only one condition “if post type is equals to product”.
But i would like to have some groups on specific product categories.
The problem is that if i select “post category” in my conditions, i have blog-categories only.
How can i achieve to unlock product categories?
Thank you in advance.
You need to build a custom location rule for WC product categories. https://www.advancedcustomfields.com/resources/custom-location-rules/
Hello, and thank you for the reply.
I’ve read your docs. But i still don’t understand how to proceed.
I basically need to add 3 options on the ‘type’ section, that are 3 product categories where i want there will be displayed only some ACF Groups.
For now, i’ve done something like that:
add_filter('acf/location/rule_values/post_category', 'acf_location_rules_values_user');
function acf_location_rules_values_user( $choices ) {
$my_filter_list = [0 => 'Books', 1 => 'Ebooks', 19091 => 'Reader'];
return $my_filter_list;
}
Before my array was 0,1,2. But i noticed that, even if i have the setting displayed on my backoffice, it’s totally not working. So i tried to change the ‘2’ with the product category ID. But is always not working.
What am i doing wrong? I maybe need to first put every category in the array?
Thank you in advance.
– Kryuko
Hello.
Is there maybe a better way to do this with ACF PRO?
Thank you in advance.
– Kryuko
Sorry for taking so long to get back to you. It takes more than just one filter to build a custom location rule and you can just tack your taxonomies onto the post category rule.
Building a complete set of location rule filters, with the exception of “Rule Operators” is the only way to do this in ACF.
I have several examples of custom location rules, but none of them are for this specific purpose, but can be used as a reference. https://github.com/Hube2/acf-filters-and-functions
The topic ‘Use product category for ACF conditions’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.