0
votes

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?

screenshot

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

1
I'de dive deeper into the documentation and try to find out where $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
Have you asked the plugin developers? Unless someone has specifically worked with this plugin and looked into this specific aspect of it I doubt you'll find anyone that can answer this with any degree of accuracy.Tony Djukic
I wrote to the support, they can't help me. I edited my question and added their tips there.Lider Budowlany

1 Answers

0
votes

Based on the source code of woocommerce you can use get_price method and it will return active price without any html

Ref.: https://github.com/woocommerce/woocommerce/blob/5007d17596855a685bd3ec3c8791e689a4e707f5/includes/abstracts/abstract-wc-product.php#L266