Skip to content

Instantly share code, notes, and snippets.

@EricBusch
Created March 8, 2017 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save EricBusch/7552c008da94b1d04bbb6505a6000fdb to your computer and use it in GitHub Desktop.
Save EricBusch/7552c008da94b1d04bbb6505a6000fdb to your computer and use it in GitHub Desktop.
This code will add the merchant logo (if the logo exists) to the loop between product thumbnail and product name. [datafeedr]
<?php
/**
* Add merchant logo (if it exists) to the Loop between product thumbnail and product name.
*/
add_action( 'woocommerce_before_shop_loop_item_title', 'mycode_add_merchant_logo_to_loop', 20 );
function mycode_add_merchant_logo_to_loop() {
global $product;
if ( dfrpswc_is_dfrpswc_product( $product->id ) ) {
$postmeta = get_post_meta( $product->id, '_dfrps_product', true );
$title = esc_attr( $postmeta['merchant'] );
$merchant = esc_html( $postmeta['merchant'] );
$url = 'https://images.datafeedr.com/m/' . $postmeta['merchant_id'] . '.jpg';
echo '<style type="text/css">.dfr_missing_logo span{display:inline;}.dfr_missing_logo img{display:none;}</style>';
echo "<img onerror='this.parentNode.className += \" dfr_missing_logo\"' src='$url' alt='$title' title='$title'><span style='display:none;'>$merchant</span>";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment