Skip to content

Instantly share code, notes, and snippets.

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/122f4a738d2eb2e4ea8042e83a260e20 to your computer and use it in GitHub Desktop.
Save EricBusch/122f4a738d2eb2e4ea8042e83a260e20 to your computer and use it in GitHub Desktop.
This code will add the merchant logo (if the logo exists) to the WooCommerce single product page. [datafeedr]
<?php
/**
* Add merchant logo (if it exists) to product details page.
*/
add_action( 'woocommerce_external_add_to_cart', 'mycode_add_merchant_logo_to_single_product_page' );
function mycode_add_merchant_logo_to_single_product_page() {
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