Home / Admin / Change the sold by label on the product archive
Duplicate Snippet

Embed Snippet on Your Site

Change the sold by label on the product archive

Code Preview
php
<?php
// Unhook WC Vendors method 
remove_action( 'woocommerce_after_shop_loop_item', array('WCV_Vendor_Shop', 'template_loop_sold_by'), 9 );
// Define new sold by method 
function wcv_new_template_loop_sold_by( $product_id ) { 
	$vendor_id         = WCV_Vendors::get_vendor_from_product( $product_id );
	// Get the products categories.
	$categories = get_the_terms( $product_id, 'product_cat' );
	// Reset the array to get the first category only. 
	$categories = reset( $categories );
	
	$class 		= isset( $css_class ) ? 'class="' . $css_class . '"' : '';
	$sold_by 	= WCV_Vendors::is_vendor( $vendor_id )
		? sprintf( '<a href="%s" %s>%s</a>', WCV_Vendors::get_vendor_shop_page( $vendor_id ), $class, 'Created by: '. WCV_Vendors::get_vendor_sold_by( $vendor_id ) . ' in '. $categories->name )
		: get_bloginfo( 'name' );
	echo '<small class="wcvendors_sold_by_in_loop">' . $sold_by. '</small><br/>';
}
// Hook new method in at the same place the WC Vendors was. 
add_action( 'woocommerce_after_shop_loop_item', 'wcv_new_template_loop_sold_by', 9 );

Comments

Add a Comment