Woocommerce Dinamic Proces and Discounts
In my woocommerce store the product’s price depends on some conditions, for this reason I use this:
add_filter('woocommerce_product_get_price', 'custom_price', 0, 2 );
add_filter('woocommerce_product_get_regular_price', 'custom_price', 0, 2 );
function custom_price( $price, $product ) {
$priceType = kibooGetCurrentUserPriceType();
$prices = kibooGetProductPrices($product->get_id());
if($prices[$priceType] > 0){
$price = $prices[$priceType];
}
return $price;
}
Get this code from here https://stackoverflow.com/questions/45806249/change-product-prices-via-a-hook-in-woocommerce-3/45807054#45807054 and works fine
Also I need to use some discounts so I’m using WooCommerce Dynamic Pricing & Discounts with AI 1.4.3
Discounts works fine only if I’m not using the filters to overwrite the products price.
I need to use the filters, change product price and AFTER this change, apply the discounts to the product.
What things have I already tried?
Contacted the plugin’s developers with no luck (they want to charge me for a customization).
Change the add_filter() priority to several values.
I have already tried to track the order in which the changes occur but it is a bit complex for me to understand.
Looked inside the plugin’s code for a clue but it is a bit over my skills.
Behavior Without Custom Price and With Discount
- Product X Price is $100
- Product X Discount is 10%
- Product X Visible Price is $100 with a “10% off” indication
- Cart shows $90 with a $10 discount.
All good
Behavior With Custom Price and Without Discount
- Product X Price is $100
- Product X Custom Price is $200
- Product X Visible Price is $200
- Cart shows $200
All good
Behavior With Custom Price and With Discount
- Product X Price is $100
- Product X Custom Price is $200
- Product X Discount is 10%
- Product X Visible Price is $200 with a “10% off” indication
- Cart shows $200 without indications of any discount
Not good
Versions
WordPress 5.5
WooCommerce 4.4.1
Dynamic Pricing & Discounts Lite for WooCommerce 1.2.2
WooCommerce Dynamic Pricing & Discounts with AI 1.4.3
Leave an answer