Last active
September 21, 2021 03:41
-
-
Save ben-heath/5f7031a4ff393e5db9b41ec0df3446cc to your computer and use it in GitHub Desktop.
Custom WooCommerce Shop Loop Product Thumbnail and Title
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 | |
/** | |
* Check if WooCommerce is active | |
**/ | |
if ( in_array( 'woocommerce/woocommerce.php', apply_filters( 'active_plugins', get_option( 'active_plugins' ) ) ) ) { | |
// remove product thumbnail and title from the shop loop | |
remove_action( 'woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10 ); | |
remove_action( 'woocommerce_before_shop_loop_item_title', 'woocommerce_template_loop_product_thumbnail', 10 ); | |
// add the product thumbnail and title back in with custom structure | |
add_action( 'woocommerce_before_shop_loop_item_title', 'sls_woocommerce_template_loop_product_thumbnail', 10 ); | |
function sls_woocommerce_template_loop_product_thumbnail() { | |
echo '<a class="thumbnail" title="'.get_the_title().'" href="'. get_the_permalink() . '">'.woocommerce_get_product_thumbnail().'</a>'; | |
echo '<h3><a href="'.get_the_permalink().'">'.get_the_title().'</a></h3>'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment