Skip to content
Advertisement

Woocommerce replace category image with AFC image

I have the following code that works and need to Replace the existing category with AFC images

add_action('woocommerce_before_subcategory_title', 'wpse_add_custom_text_under_category_title', 10);

function wpse_add_custom_text_under_category_title($category) {
   $term_id = 'product_cat_'.$category->term_id;
    echo'<ol class="carousel__viewport">';
for ( $i = 1; $i <= 3; $i++ ){  
  $category_image =  '<img src="'.get_field('category_image_' . $i, $term_id).'"/>';
 if( $category_image ) {
    echo '<li id="carousel__slide" tabindex="0" class="carousel__slide">'.$category_image.'<div class="carousel__snapper"></div></li>';
  } else {
    echo '';
}
}
    echo'</ol>';
}

this scrolls but now the default images are in their place first screenshot of admin panel enter image description here

frontend screenshot

enter image description here

how can I remove the default once

Advertisement

Answer

Just remove default one

remove_action( 'woocommerce_before_subcategory_title', 'woocommerce_subcategory_thumbnail', 10 );

Add this in to your theme functions.php

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement