PluginUs.Net - Business Tools for WooCommerce and WordPress

[realize your idea - make your dreams come true]

Support Forum

You need to log-in to create request (topic) to the support

Unable to get correct price when using fixed price rule for products

The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday. If you have problems with registration ask help on contact us page please
If you not got email within 24~36 business hours, firstly check your spam box, and if no any email from the support there - back to the forum and read answer here. DO NOT ANSWER ON EMAILS [noreply@pluginus.net] FROM THE FORUM!! Emails are just for your info, all answers should be published only here.
The support doesn work on Saturdays and Sundays, so some Friday requests can be answered on Monday.

I have set up WOOCS to use fixed price rules for certain products and everything seems to be working just fine. My problem is that when I try to get the price of the product using custom code. I tried these two options

$price = wc_get_price_to_display( $product );

or

$price = $product->get_price();

The price I get is the one obtained by converting the default price uusing the conversion rate as opposed to the fixed price that I set up for the product.

Can you please help me out? Is there a filter/action or other function I should be using in my custom code?

Thanks in advance

Hello

Try  to use  $price = $product->get_price('view'); OR  $price = $product->get_price('edit');

Hi Pablo, thanks a lot.

Unfortunatelly it didn't work.

$price = $product->get_price('view') returns the same automatically converted:   [default_woo_price] * [conversion_rate]

$price = $product->get_price('edit') returns the default WooCommerce price

Any other ideas?

Hello

Very strange! My plugin inserts fixed prices in the same function as conversion.

In other words, if there is no fixed price, then there should be no conversion.

Code  to  get  fixed price:

global $WOOCS;

if ($WOOCS->is_fixed_enabled) {
if ($WOOCS->is_multiple_allowed AND $product !== NULL AND is_object($product)) {

//if (isset($product->variation_id))
if ($product->is_type('variation')) {

$price = $WOOCS->_get_product_fixed_price($product, 'variation', $price, $precision);
} elseif ($product->is_type('variable')) {
$price = -1;
} else {
$price = $WOOCS->_get_product_fixed_price($product, 'single', $price, $precision);
}}
}

Hi Pablo, thanks again for your prompt response.

 

I was able to narrow down the problem. The issue seems to occur only when I use the get_price() function on a variable product.

All attempts to get the price of any of the variations return the correct price.

All of this analysis got me thinking. I'm not sure what WooCommerce returns when calling get_price() on a variable product (all my variations have the same price so it never occurred to me that a variable product might have multiple prices)

Maybe this can help. Any ideas?

Hello

Yes it can cause a problem. Because the fixed prices have a key with the ID of the products, in this case  ID  of  variation

In any case : you want to use the custom code I gave above

Or take any product variant and get a fixed price from that variant

 

Thanks a lot Pablo!

 

I had a look at what WooCommerce does to retrieve the price of a varable product and I replicated the same code (getting the price of its variations).

Since the price of the variations are correct I can use this workaround.

Once again thanks a lot.

Hello

Great!  Welcome;)