Support

Account

Forum Replies Created

  • Following along with the instructions within the link, I’m able to accomplish all the steps except for “Matching the Rule” to the Category Editor page (Sorry for the sloppy code).

    add_filter('acf/location/rule_types', 'acf_location_rules_types');
    
    function acf_location_rules_types( $choices ) {
    	
        $choices['WooCommerce Category']['woocommerce_category'] = 'WooCommerce Category';
    
        return $choices;
        
    }
    
    add_filter('acf/location/rule_values/woocommerce_category', 'acf_location_rules_values_woocommerce_category');
    
    function acf_location_rules_values_woocommerce_category( $choices ) {
    	
    	$args = array(
    	    'number'     => $number,
    	    'orderby'    => $orderby,
    	    'order'      => $order,
    	    'hide_empty' => $hide_empty,
    	    'include'    => $ids
    	);
    	
    	$product_categories = get_terms( 'product_cat', $args );
    
     
    
        if( $product_categories ) {
    	    
            foreach( $product_categories as $cat ) {
    	        
                $choices[  $cat->name ] =  $cat->name;
                
            }
            
        }
    
        return $choices;
    }
    
    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 )
    {
        $args = array(
    	    'number'     => $number,
    	    'orderby'    => $orderby,
    	    'order'      => $order,
    	    'hide_empty' => $hide_empty,
    	    'include'    => $ids
    	);
    	
    	$product_categories = get_terms( 'product_cat', $args );
    	
    	$selected_category = (int) $rule['My Product Category Name'];
    	
    
        if($rule['operator'] == "==")
        {
        	foreach( $product_categories as $cat ) {
    	        
                $match = ( $cat->name == $selected_category );
                
            }
        }
    
        return $match;
    }
  • Hi James,

    Thanks for pointing me in the right direction. I’m not the best with creating custom function items, but I’ll do some trial and error to see if I can accomplish showing the fields on a certain term page editor.

    Thanks again!

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