Add merchant logo to product details page

This article explains how to add a merchant logo (if the logo exists in our database) to the single product page like this:

Merchant logo on single product page.
1

Create a custom plugin

If you haven't done so already, create a custom plugin.

2

Add custom code

Add the following custom code to your custom plugin.

add_action( 'woocommerce_external_add_to_cart', function () {

   global $product;

   if ( ! dfrpswc_is_dfrpswc_product( $product->get_id() ) ) {
      return;
   }

   $postmeta    = get_post_meta( $product->get_id(), '_dfrps_product', true );
   $title       = esc_attr( $postmeta['merchant'] ?? '' );
   $merchant    = esc_html( $postmeta['merchant'] ?? '' );
   $merchant_id = absint( $postmeta['merchant_id'] ?? 0 );
   $url         = esc_url( sprintf( 'https://images.datafeedr.com/m/%d.jpg', $merchant_id ) );

   printf( '<object data="%s" type="image/jpeg" title="%s">%s</object>', $url, $title, $merchant );

}, 20 );
	
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us