38 lines
1.5 KiB
PHP
38 lines
1.5 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);
|
|
|
|
// Also hook into cart and checkout prices
|
|
add_filter('woocommerce_cart_item_price', 'sodino_apply_to_cart_item', 10, 3);
|
|
add_filter('woocommerce_cart_item_subtotal', 'sodino_apply_to_cart_item', 10, 3);
|
|
|
|
function sodino_apply_dynamic_pricing($price, $product) {
|
|
global $sodino_pricing_service;
|
|
return $sodino_pricing_service->applyDynamicPricing($price, $product);
|
|
}
|
|
|
|
function sodino_apply_to_cart_item($price, $cart_item, $cart_item_key) {
|
|
global $sodino_pricing_service;
|
|
$product = $cart_item['data'];
|
|
return wc_price($sodino_pricing_service->applyDynamicPricing($product->get_price(), $product));
|
|
} |