Код такой
public function list_products_html( $lang = false ) {
ob_start();
/**
* WPML Suppot: Localize Ajax Call
*/
global $sitepress;
if( defined( 'ICL_LANGUAGE_CODE' ) && $lang && isset( $sitepress )) {
$sitepress->switch_lang( $lang, true );
}
if ( empty( $this->products_list ) ) {
echo '' . __( 'No products to compare', 'yith-woocommerce-compare' ) . '';
return ob_get_clean();
}
$count = 0;
foreach ( $this->products_list as $product_id ) {
/**
* @type object $product /WC_Product
*/
$product = $this->wc_get_product( $product_id );
$count++;
?>
<?php
}
echo $count;
$return = ob_get_clean();
return apply_filters( 'yith_woocompare_widget_products_html', $return, $this->products_list, $this );
}
и в шаблоне
<?php global $yith_woocompare;
echo $yith_woocompare->obj->list_products_html();
?>