Created
June 15, 2015 17:34
-
-
Save bekarice/03cfe31c3308ecb9648d to your computer and use it in GitHub Desktop.
conditionally add images above product images in the shop loop via a product's custom field
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
// Requires that you set a custom field on the product with logo_src = image url | |
function sv_add_logo_above_wc_shop_image() { | |
global $product; | |
// replace the custom field name logo_src with your own | |
$logo_src = get_post_meta( $product->id, 'logo_src', true ); | |
// Add these fields to the shop loop if set | |
if ( ! empty( $logo_src ) ) { | |
echo '<img src="' . $logo_src . '" class="aligncenter" style="margin-bottom: 20px;" />'; | |
} | |
} | |
add_action( 'woocommerce_before_shop_loop_item_title', 'sv_add_logo_above_wc_shop_image', 9 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment