Init(Core): create and add project
This commit is contained in:
34
public/hooks/pricing-hooks.php
Normal file
34
public/hooks/pricing-hooks.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
// Prevent direct access
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
use Sodino\Services\PricingService;
|
||||
use Sodino\Repositories\RuleRepository;
|
||||
|
||||
// Initialize pricing service
|
||||
global $sodino_pricing_service;
|
||||
$ruleRepository = new RuleRepository();
|
||||
$sodino_pricing_service = new PricingService($ruleRepository);
|
||||
|
||||
// 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));
|
||||
}
|
||||
Reference in New Issue
Block a user