Forked from EricBusch/add-merchant-logo-to-loop.php
Last active
November 3, 2017 15:11
-
-
Save EricBusch/3e764b7762b6c5a7245b1c0ff3b8818a 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]
This file contains 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
<?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->get_id() ) ) { | |
$postmeta = get_post_meta( $product->get_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