Forked from yanknudtskov/wc-categories-fallaback-image.php
Created
June 18, 2018 06:37
-
-
Save INDIAN2020/f9fc50950a1e7ce11aaaf558d2371fe0 to your computer and use it in GitHub Desktop.
Remember to upload fallback-image.png to /wp-content/THEME_NAME/images where THEME_NAME is name of the directory of the active theme #woocommerce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| add_action( 'woocommerce_archive_description', '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="" />'; | |
| } else { | |
| $fallback_image_url = get_stylesheet_directory_uri() . '/images/fallback-image.png'; | |
| echo '<img src="' . $fallback_image_url . '" alt ="" />'; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment