In my wordpress with woocommerce I use plugin Pricing deals rules, which dynamically adds discount for products.
In catalog product display price for example:
49,00 34,30
Now I want to add in my theme a custom badge with percentage discount, so I want to calculate percentage from sale price and regular price.
I can store regular price in variable by $product->regular_price;
But $product->sale_price or $product->get_sale_price() doesn't exist in this plugin.
So my idea is to str_replace the $product->get_price_html(), because this returns sale price in html tags. But the problem is with getting output from this function to a variable, when I try $content = $product->get_price_html(); nothing happens, so I suspect this function echo the output, not return output. So is there a way to get output of this function to a variable? Or maybe some other way to achieve sale price?
I wrote to support, they answer that they can't help me with this, and I got only this instructions:
I'd suggest investigating using the WOO filter 'woocommerce_get_price_html' which will deliver the discounted price to you (it's the filter that activates the function I suggested you emulate).
Suggest you investigate (a) how to use filters in WP (b) look for the suggested filter in the WOO plugin code, to learn how it should be called, and what results. (c) gather the info the filter needs, place the call to the filter in your theme, use the result.
Can someone please help me with that? Please
$product->get_price_html();
gets its adjusted price from (since it must have some source of data) which would be a lot better than a work around. – Remy