0

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

  1. Product X Price is $100
  2. Product X Discount is 10%
  3. Product X Visible Price is $100 with a "10% off" indication
  4. Cart shows $90 with a $10 discount.

All good

Behavior With Custom Price and Without Discount

  1. Product X Price is $100
  2. Product X Custom Price is $200
  3. Product X Visible Price is $200
  4. Cart shows $200

All good

Behavior With Custom Price and With Discount

  1. Product X Price is $100
  2. Product X Custom Price is $200
  3. Product X Discount is 10%
  4. Product X Visible Price is $200 with a "10% off" indication
  5. 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
  • I have no idea how those plugins work but I assume they're still using the built-in WC_Cart_Totals class? I'd try debugging calculate_item_subtotals() and calculate_discounts() in that class to work out what's going wrong. – Rup Aug 25 at 23:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.