nowa-panda/plugins/pandaGadzety/utils/modify-product-name.php

42 lines
1.0 KiB
PHP
Raw Normal View History

2025-07-07 07:51:16 +00:00
<?php
namespace Foxstudio\Plugins\Template\Utils;
use \Foxstudio\Plugins\Template\Repository\ProductRepository;
class ShowMinimumPrice {
public function __construct()
{
\add_action('woocommerce_shop_loop_item_title', [$this, 'change_product_title']);
\remove_action('woocommerce_shop_loop_item_title', 'woocommerce_template_loop_product_title', 10);
}
function change_product_title()
{
global $product;
if (!$product) {
return;
}
// $price = 85.56;
$sku = $product->get_sku();
$price = $product->get_price();
$price = $this->getLowestPrice($price);
echo '<h2 class="woocommerce-loop-product__title">' . get_the_title() . '</h2><p style="font-weight: 700;">od ' . $price . ' zł</p>';
}
private function getLowestPrice($price) {
$productRepository = new ProductRepository(SERVER_URL);
$price = $productRepository->getLowestPrice($price);
return $price;
}
}