Support

Account

Forum Replies Created

  • FWIW, I kept at it and built my own solution. I need to do another re-read of the documentation page to make sure I’m using both hooks correctly, but it at least works for now.

    // Add WooCommerce 'Shop' location rule value
    // https://www.advancedcustomfields.com/resources/custom-location-rules/
    add_filter('acf/location/rule_values/page_type', 'dc_acf_location_rules_values_woo_shop');
    
    function dc_acf_location_rules_values_woo_shop($choices){
    
    	$choices[ 'woo-shop-page' ] = 'WooCommerce Shop Page';
    
    	return $choices;
    }
    
    // Add WooCommerce 'Shop' location rule match
    add_filter('acf/location/rule_match/page_type', 'dc_acf_location_rules_match_woo_shop', 10, 3);
    
    function dc_acf_location_rules_match_woo_shop($match, $rule, $options){
    	if(is_admin() && $rule['value'] == 'woo-shop-page'){
    		$post_id = $options['post_id'];
    		$woo_shop_id = get_option( 'woocommerce_shop_page_id' );
    
    		if($rule['operator'] == "=="){
    			$match = $post_id == $woo_shop_id;
    		}elseif($rule['operator'] == "!="){
    			$match = $post_id != $woo_shop_id;
    		}
    	}
    
      return $match;
    }
  • +1 on this, but in the mean-time, I’ve created a workaround. Simply use a “Taxonomy” as a select or radio (single value) field, and to get a link to that taxonomy archive, use:
    get_category_link( get_field( 'your-taxonomy-field' ) )

    for example, I used it in this way:
    printf( '<a href="%1$s">Your Category</a>', get_category_link( get_field( 'your-taxonomy-field' ) ) );

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