varunsridharan / woocommerce-role-based-price

WooCommerce Role Based Price Plugin
https://codecanyon.net/item/woocommerce-role-based-pricing-pro/14120734
GNU General Public License v3.0
48 stars 22 forks source link

Discount assigned to role doesn't work if you do not have a general discount on the product (no role) #128

Open rafaelcalero opened 4 years ago

rafaelcalero commented 4 years ago

Describe the bug Discount assigned to role doesn't work if you do not have a general discount on the product (no role).

To Reproduce Steps to reproduce the behavior:

  1. Create product without discount in woocommerce.
  2. Assign regular price and sale price to a role.
  3. The user with that role will get the discounted price, but will not receive the crossed out price indicating that it is on sale.

Expected behavior They should appear in the format wc_format_sale_price()

Additional context

The problem seems to be in the WooCommerce_Role_Based_Price_Product_Pricing->get_price_html_wc3();

$product->is_on_sale() returns false because for wordpress that product is not on sale.

             ...
        } else if( $product->is_on_sale() && $prices['min_reg_price'] === $prices['max_reg_price'] ) {
            $price = wc_format_sale_price(wc_price($prices['max_reg_price']), wc_price($prices['min_price']));
        } else {
             ....

A possible fix could be add filter on the woocommerce_product_is_on_sale hook and modify this value for products that they have different regular and sale price or perhaps put one more condition in that same function.

Regards