Support

Account

Home Forums Backend Issues (wp-admin) Custom Field on Certain WooCommerce Product Category Page Reply To: Custom Field on Certain WooCommerce Product Category Page

  • 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;
    }