Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bekarice/03cfe31c3308ecb9648d to your computer and use it in GitHub Desktop.
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
// 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