Created
March 8, 2017 13:57
-
-
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]
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->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