Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save EricBusch/51ae03e229c106119a83801b315851a5 to your computer and use it in GitHub Desktop.
Save EricBusch/51ae03e229c106119a83801b315851a5 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.
*
* This displays the merchant's logo before the [buy now] button on
* single product detail pages.
*
* @global WC_Product $product
*/
function mycode_add_merchant_logo_to_single_product_page() {
global $product;
if ( ! dfrpswc_is_dfrpswc_product( $product->get_id() ) ) {
return;
}
$postmeta = get_post_meta( $product->get_id(), '_dfrps_product', true );
$merchant_id = absint( $postmeta['merchant_id'] );
$merchant_name = esc_html( $postmeta['merchant'] );
$img_alt = esc_attr( $postmeta['merchant'] );
$url = 'https://images.datafeedr.com/m/' . $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='$img_alt' title='$img_alt'><span style='display:none;'>$merchant_name</span>";
}
add_action( 'woocommerce_external_add_to_cart', 'mycode_add_merchant_logo_to_single_product_page' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment