I am using a hook to change the appearance of categories on my website.
my problem is, it works fine for product categories but when i decided to use a custom taxonomy for the purpose, they are appearing but without their image ( i set an image field up with ACF for the custom tax ; return format image array ) it is the custom tax term image that is missing whereas everything else works ( the custom tax link, and name are showing )
I have no idea where I am going wrong with it, i have tried endless amounts of different things, it cannot find the thumbnail ID of the custom taxonomy.
Can anybody give me some advice please.
if ( ! function_exists('custom_subcategory_thumbnail') ):
remove_action('woocommerce_before_subcategory_title', 'woocommerce_subcategory_thumbnail');
add_action('woocommerce_before_subcategory_title', 'custom_subcategory_thumbnail', 10, 1);
function custom_subcategory_thumbnail( $category ) {
$thumbnail_id = get_term_meta( $category->term_id, 'thumbnail_id', true );
/* echo '<pre>';
var_dump($testing);
echo '</pre>';*/
// var_dump($thumbnail_id);
// $taxonomy = $queried_object->taxonomy;
// $wpimage = get_field('workplace_thumb', 'workplaces' . '_' . $category->term_id);
/* echo '<pre>';
print_r($thumbnail_id);echo '</pre>';*/
// $attachment_id = get_field( 'workplace_thumb', 'workplaces_' . $category->term_id );
/*
echo '<pre>';
print_r($attachment_id);
echo '</pre>';*/
if ( $thumbnail_id ) {
$image = wp_get_attachment_image_src( $thumbnail_id, 'woocommerce_single' );
$image = $image[0];
$image_srcset = function_exists( 'wp_get_attachment_image_srcset' ) ? wp_get_attachment_image_srcset( $thumbnail_id, 'shop_single_image_size' ) : false;
$image_sizes = function_exists( 'wp_get_attachment_image_sizes' ) ? wp_get_attachment_image_sizes( $thumbnail_id, 'shop_single_image_size' ) : false;
}
else{
$image = wc_placeholder_img_src();
$image_srcset = $image_sizes = false;
}
if ( $image ) {
// Prevent esc_url from breaking spaces in urls for image embeds
// Ref: https://core.trac.wordpress.org/ticket/23605
$image = str_replace( ' ', '%20', $image );
echo '<div class="banner-box__image brand-grayscale">
<a href="' . esc_url( get_term_link( $category, 'product_cat' ) ) . '" >
<span class=" woocommerce-loop-category__thumbnail brand-grayscale" style="background-image :url(' . esc_url( $image ) . ');"></span></a>
</div>';
}
}
endif;