• Resolved JeanineH93

    (@jeanineh93)


    Hi there,

    On the product archive page I want to show the logo of the vendor at every product.
    I am using the following snippet, which is working perfect:

    // LOGO BEFORE SOLD BY TEXT
    add_filter('wcmp_sold_by_text', 'show_image_callback', 10, 2);
    
    function show_image_callback($text, $post_id) {
    	$vendor = get_wcmp_product_vendors($post_id);
    	$img_id = $vendor->image;
    	$image = '<img src="'.wp_get_attachment_url( $img_id ).'" style="height:100%!important;"/>';
    	$new_text = $text . " " . $image;
    	return $new_text;
    }

    However, this is displaying both the logo and the “Sold by: Vendor” text.
    I would like to disable the “Sold by: Vendor” text and only show the logo.
    How do I do this?

Viewing 5 replies - 1 through 5 (of 5 total)
  • @jeanineh93, this hook will always show sold by text.

    Hence you need to use this hook woocommerce_after_shop_loop_item_title, and add your code.

    Also, disable the “Enable “Sold by” option via WCMp >> Settings >> General.

    Let us know if you have any further query.

    Thread Starter JeanineH93

    (@jeanineh93)

    Hi there,
    Thank you for your answer.
    I have tried it with the following code:

    // LOGO BEFORE SOLD BY TEXT
    function show_image_callback($text, $post_id) {
    	$vendor = get_wcmp_product_vendors($post_id);
    	$img_id = $vendor->image;
    	$image = '<img src="'.wp_get_attachment_url( $img_id ).'" style="width:100%!important;max-height:60px!important;object-fit:contain!important;"/>';
    	$new_text = $text . " " . $image;
    	return $new_text;
    }
    add_action('woocommerce_before_shop_loop_item_title', 'show_image_callback', 10, 2);

    However, this is not displaying the image at all. I have disabled the “Sold by” option in the WCMp settings.

    Is there something wrong with the code?

    @jeanineh93 You are calling woocommerce hook with our provided hook parameters, which is not valid for woocommerce hook. Here is the follows code snippet –

    // LOGO BEFORE SOLD BY TEXT
    function show_image_callback() {
        global $product;
        if( $product ) {
            $vendor = get_wcmp_product_vendors( $product->get_id() );
            if( $vendor ) {
                // $vendor->get_image() function returns default vendor logo url
                $image = '<img src="' . $vendor->get_image() . '" style="width:100%!important;max-height:60px!important;object-fit:contain!important;"/>';
                echo $image;
            }
        }
    }
    add_action( 'woocommerce_before_shop_loop_item_title', 'show_image_callback' );
    Thread Starter JeanineH93

    (@jeanineh93)

    That’s great, it’s working perfect now.
    However, and I’m sorry for the question, is it possible to link the logo image to the vendor page? Just like how the “sold by” text was linked to the vendor page.

    @jeanineh93 just replace the above code line $image = '<img src="' . $vendor->get_image() . '" style="width:100%!important;max-height:60px!important;object-fit:contain!important;"/>'; with $image = '<a href="' . $vendor->permalink . '"><img src="' . $vendor->get_image() . '" style="width:100%!important;max-height:60px!important;object-fit:contain!important;"/></a>';

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Display vendor logo instead of “Sold By” text’ is closed to new replies.