nowa-panda/plugins/pandaGadzety/utils/logistic-minimum.php

37 lines
948 B
PHP
Raw Permalink Normal View History

2025-07-07 07:51:16 +00:00
<?php
namespace Foxstudio\Plugins\Template\Utils;
class LogisticMinimum {
private int $minimumOrderPrice, $fee;
public function __construct($minimumOrderPrice, $fee)
{
$this->minimumOrderPrice = $minimumOrderPrice;
$this->fee = $fee;
\add_action('woocommerce_cart_calculate_fees', [$this, 'wc_add_surcharge']);
}
function wc_add_surcharge($cart)
{
$total_price = 0;
foreach ($cart->get_cart() as $cart_item) {
if (isset($cart_item['custom_data']['technology'])) {
$price = $cart_item['data']->get_price();
$quantity = $cart_item['quantity'];
$total_price += $price * $quantity;
}
}
if ($total_price < $this->minimumOrderPrice && $total_price > 0):
$cart->add_fee('Minimum logistyczne (dla zamówień poniżej 350 zł)', $this->fee);
endif;
}
}