Add merchant logo to loop

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

Merchant logo in the Loop.
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_before_shop_loop_item_title', 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