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