35 lines
1.3 KiB
PHP
35 lines
1.3 KiB
PHP
<?php
|
|
// Prevent direct access
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
use Sodino\Services\PricingService;
|
|
use Sodino\Services\TrackingService;
|
|
use Sodino\Repositories\RuleRepository;
|
|
use Sodino\Repositories\EventRepository;
|
|
|
|
// Initialize pricing service
|
|
global $sodino_pricing_service;
|
|
$ruleRepository = new RuleRepository();
|
|
$eventRepository = new EventRepository();
|
|
$trackingService = new TrackingService($eventRepository);
|
|
$sodino_pricing_service = new PricingService($ruleRepository, $trackingService);
|
|
|
|
// Hook into WooCommerce price filter
|
|
add_filter('woocommerce_product_get_price', 'sodino_apply_dynamic_pricing', 10, 2);
|
|
add_filter('woocommerce_product_get_sale_price', 'sodino_apply_dynamic_pricing', 10, 2);
|
|
add_filter('woocommerce_product_variation_get_price', 'sodino_apply_dynamic_pricing', 10, 2);
|
|
add_filter('woocommerce_product_variation_get_sale_price', 'sodino_apply_dynamic_pricing', 10, 2);
|
|
add_filter('woocommerce_package_rates', 'sodino_apply_free_shipping_rules', 20, 1);
|
|
|
|
function sodino_apply_dynamic_pricing($price, $product) {
|
|
global $sodino_pricing_service;
|
|
return $sodino_pricing_service->applyDynamicPricing($price, $product);
|
|
}
|
|
|
|
function sodino_apply_free_shipping_rules($rates) {
|
|
global $sodino_pricing_service;
|
|
return $sodino_pricing_service->applyFreeShippingRates($rates);
|
|
}
|