Support

Account

Home Forums Front-end Issues Can't display a Custom field in parent level taxonomy Reply To: Can't display a Custom field in parent level taxonomy

  • This stops the woocommerce loop rendering. It seems to break at:

    $child_terms = get_terms($args);

    What i’m trying to achieve is that each sub category has a colour. This is defined with the ACF colour picker. That then creates an inline style which gives each subcategory a border, defines button colours etc etc.

    The $term = get_queried_object(); works fine inside the woocommerce product loop when viewing the sub category and children of it, but not on the parent, which would essentially show a number of sub categories with there own colours defined by the ACF field.

    So this is my current loop thats working on sub categories to help explain better.

    global $product;
    
    // Ensure visibility
    if ( empty( $product ) || ! $product->is_visible() ) {
    	return;
    }
    
    // Colour Picker Setup
    $term = get_queried_object();
    $color = get_field('course_colour', $term); // Get ACF Field
    //echo  $color;
    $remove = substr($color, 0, -1); // RGBA for opacity block over image, remove last )
    $opacity = $remove . '.8)'; // RGBA for opacity block over image, add .5) to straing
    $chop = substr($color, 0, -3); // For inline styles, we need to remove the alpha value
    $border = $chop . ')'; // add closing bracket to inline style
    //echo $opacity;
    ?>
    <div class="col-md-4">
    
    	
      
    
      <div class="product-img">
    
    	<?php
    	/**
    	 * woocommerce_before_shop_loop_item hook.
    	 *
    	 * @hooked woocommerce_template_loop_product_link_open - 10
    	 */
    	do_action( 'woocommerce_before_shop_loop_item' );
    
    	/**
    	 * woocommerce_before_shop_loop_item_title hook.
    	 *
    	 * @hooked woocommerce_show_product_loop_sale_flash - 10
    	 * @hooked woocommerce_template_loop_product_thumbnail - 10
    	 */
    	do_action( 'woocommerce_before_shop_loop_item_title' );
    
    	?>
        <div class="overlay" style="background-color: <?php echo $opacity; ?>"></div>
    
    </div>
       <div class="product-box" style="color: <?php echo $border; ?> !important; border-style: solid; border-width: 4px; border-color: <?php echo $border; ?>">
    
    <div class="type" style="background: <?php echo $border; ?> ">AQA/WJEC LEVEL 3</div>
    
        <?php 
    	/**
    	 * woocommerce_shop_loop_item_title hook.
    	 *
    	 * @hooked woocommerce_template_loop_product_title - 10
    	 */
    	do_action( 'woocommerce_shop_loop_item_title' );
    
    	?>
    <div class="row">
    
    	<div class="col-md-6">
    	<?php
    	/**
    	 * woocommerce_after_shop_loop_item hook.
    	 *
    	 * @hooked woocommerce_template_loop_product_link_close - 5
    	 * @hooked woocommerce_template_loop_add_to_cart - 10
    	 */
    	do_action( 'woocommerce_after_shop_loop_item' );
    	?>
    	</div>
    	<div class="col-md-6">
    		<?php echo do_shortcode("[ti_wishlists_addtowishlist]"); ?>
    	</div>
    </div>
    
    	
    
        
    
    </div>