In fact, it needs some additional code to work like a charm :
add_filter('acf/location/rule_match/woocommerce_category', 'acf_location_rules_match_woocommerce_category', 10, 3);
function acf_location_rules_match_woocommerce_category( $match, $rule, $options )
{
global $post;
$terms = get_the_terms( $post->ID, 'product_cat' );
$selected_category = (string) $rule['value'];
if ( $terms && ! is_wp_error( $terms ) ) {
if ( $rule['operator'] == "==" ) {
foreach ( $terms as $term ) {
$match = ( $term->name == $selected_category );
}
} elseif ( $rule['operator'] == "!=" ) {
foreach ( $terms as $term ) {
$match = ( $term->name != $selected_category );
}
}
}
return $match;
}
Hello,
I think it’s because of this line :
$selected_category = (int) $rule['My Product Category Name'];
It’s not an integer and it should be ‘value’ instead of ‘My Product Category Name’ I think, so :
$selected_category = (string) $rule['value'];
Works for me.
Regards,
Deodat
Well I’ve deleted and re-created my custom field (color picker for taxonomy term) with the version 5.2.1 and it worked (doesn’t understand why it didn’t work with my old custom field but I don’t care)
Doesn’t work for me 🙁
Indeed the term taxonomy is now well assigned after updating but the custom field defined with this condition (i.e. color picker) doesn’t appear in my custom taxonomy as it did in 5.1.9
I’m rolling back to this last workin version.
The same, the last update 5.2.1 doesn’t solve the issue. Hélas.
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.