Change or Remove ‘Sold By’ Text By Page

This snippet will change or remove the “Sold By” text depending on which page you want it on. On my site, I wanted to change the “Sold By” to “Vendor”, but WCMp has coding errors that make it so you can’t just use Loco Translate.

I wanted it to say “Vendor: XYZ” in cart and checkout… WCMP hard codes a colon symbol and spaces, so for those pages you have to remove it from the text. Next, I wanted to completely remove this text on my home page, shop page, and category pages since the product carousel is very narrow and some of my vendor names are quite long. Finally, I wanted to display the full text as with the cart and checkout on the single product pages. So in this case, we needed to have the colon symbol and spaces in our code.

As always, this is either added to your Child Theme’s functions.php file, or consider using the My Custom Functions Pro plugin to manage and organize all your snippets.

add_filter('wcmp_sold_by_text', 'sold_by_show_only_certain_pages' );
function sold_by_show_only_certain_pages ($sold_by_text) {
    
    if ( is_cart() || is_checkout() ) {
        $sold_by_text = 'Vendor'; // NO colon symbol here or two will be displayed.
		return $sold_by_text;
    }         
    
	if( is_front_page() || is_shop() || is_product_category() ) {
        $sold_by_text = '';  // Effectively removes the Sold By Text.
		return $sold_by_text;
    }  
    
	if( is_product() ) {
        $sold_by_text = 'Vendor: '; // With the colon and spaces.  Make text whatever you want.
		return $sold_by_text;
    }  
}

Comments on this post

Your email address will not be published. Required fields are marked *