Support

Account

Home Forums Backend Issues (wp-admin) Trying to add field group to the WooCommerce 'Shop' page (only) Reply To: Trying to add field group to the WooCommerce 'Shop' page (only)

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