Skip to content

Instantly share code, notes, and snippets.

@joeyz
Created October 13, 2014 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joeyz/2f7964711786bee1ef09 to your computer and use it in GitHub Desktop.
Save joeyz/2f7964711786bee1ef09 to your computer and use it in GitHub Desktop.
WooCommerce Add header image with the categories thumnail
<div class="row">
<div class="archive-header">
<?php
//firs argument of the action is WHERE the function hooks into
add_action( 'woocommerce_before_main_content', 'woocommerce_category_image', 2 );
function woocommerce_category_image() {
if ( is_product_category() ){
global $wp_query;
$cat = $wp_query->get_queried_object();
$thumbnail_id = get_woocommerce_term_meta( $cat->term_id, 'thumbnail_id', true );
$image = wp_get_attachment_url( $thumbnail_id );
if ( $image ) {
echo '<img src="' . $image . '" alt="" />';
}
}
} ?>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment