Skip to content

Display plugin result to product list page

I created a plugin file for showing some extra data on product detail page. May I know how to display the result to the product list? Thanks

app/code/Myvendor/Mymodule/Plugin/GeoModel.php

<?php

namespace MyvendorMymodulePlugin;

use MyvendorMymoduleHelperGeoLocation;

use MagentoCatalogBlockProductListProduct;

class GeoModel {

   public function __construct(
       GeoLocation $geoLocation
   )
   {
       $this->geoLocation=$geoLocation;
   }

   public function afterGetProductCollection(MagentoCatalogBlockProductListProduct $subject, $result) {
       foreach($result as $value) {
           $value->setData("ip", $this->geoLocation->getCountryCodeByIp()) ;
       }
       return $result;

   }


}