Skip Navigation

[Resolved] Problems with "Save price" in Woocommerce

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 10 replies, has 3 voices.

Last updated by thomasS-11 6 years, 9 months ago.

Assigned support staff: Luo Yang.

Author
Posts
#285224

Hi.

I have made a carousel view that has "Saved amount in percentage".
The view is actually working - but some products doesnt eventhough they ARE on sale.

I have created it by adding this in my functions.php

add_shortcode('wpv-calculate', 'calculate_shortcode');
function calculate_shortcode($atts,$content=null) {
$content = wpv_do_shortcode($content);
$content = eval('return ' . $content . ';');
return round($content);
}

This is the view

          [wpv-if arg_1="views_woo_on_sale" evaluate="$arg_1 = '1'"]
          <div class="callout style1">
            <div class="inner">
              <div class="inner-text">-[wpv-calculate]
([wpv-post-field name="_regular_price"]-[wpv-post-field name="_sale_price"])*100/[wpv-post-field name="_regular_price"]
[/wpv-calculate]%
              </div>
            </div>
          </div>
          <!-- end callout -->
          [/wpv-if]

You can see in the carousel that the last products are showing -0% but when you see the single product, it displays the real saved amount (default from theme).

Further more, i get this error message when i use the view.
Parse error: syntax error, unexpected ')' in /home/u1364wi/www/wp-content/themes/flatsome-child/functions.php(133) : eval()'d code on line 2 Parse error: syntax error, unexpected ')' in /home/u1364wi/www/wp-content/themes/flatsome-child/functions.php(133) : eval()'d code on line 2 Parse error: syntax error, unexpected ')' in /home/u1364wi/www/wp-content/themes/flatsome-child/functions.php(133) : eval()'d code on line 2 Parse error: syntax error, unexpected ')' in /home/u1364wi/www/wp-content/themes/flatsome-child/functions.php(133) : eval()'d code on line 2

The site affected by this is problem is hidden link

Since the problem consists, i chose to remove the slider from the front page due to the error.
You can see the error in a test page here though: hidden link

Thank you.

#285251

Hi Thomas,

You have 4 errors and 4 products showing -0%, I'm sure those errors want to say something. Let's investigate one product and the solution should solve everything. Let's take this one:

hidden link

Please use a database management software and check both "_regular_price" and "_sale_price" on postmeta table.

Also, I have another suggestion for you. As you are working with numbers, it's good to pass the string ("_regular_price" value, for instance) to the PHP function. It lets you work with those values and one thing I'd recommend you is to convert those values to float making the calculation directly inside of the function. So that function should return the calculated value.

Please let me know if you are satisfied with my reply and any other questions you may have.

Regards,

Adriano Ferreira

#285255

Hi Adriano.
Thanks for supporting me.

What should i check for in the database? - i mean what values?

Im not experienced with PHP sorry, could you please provide me a working example?

Thanks again.

#285281

Hi Thomas,

I need to request temporary access (wp-admin and FTP) to your site in order to be offering better help. You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

#285705

I've just figured it out, the issue is happening with variable products. The variable product doesn't has a fixed "_regular_price" so it won't work fine. It's a WooCommerce thing, not Views.

Please let me know if you are satisfied with my reply and any other questions you may have.

Regards,

Adriano Ferreira

#285799

Is there any alternative way of showing the saved amount? - the theme has the feature in the theme, so woocommerce views should be able to do it?
isnt it possible to do it the same way?

Thank you

#285987

I appreciate your help, but maybe Luoy who helped me with the calculation can answer better?
-i dont know, im just asking

#286207

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Dear Thomas,

I agree with Adriano:
The issue is happening with variable products. The variable product doesn't has a fixed "_regular_price" so it won't work fine. It's a WooCommerce thing, not Views.

And you can try add a filter to avoid those variable products, for example:
edit your view "Forside produktslider", add a filter:
_sale_price !=
hidden link

See the result:
hidden link

#286298

Thanks.

Well in geppel.dk/test i can see that its showing the correct percentage after the calculation is showed?

also, the slider is only showing "Sale" products, so they should all have a regular price..

#286781

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Yes, you are right, they should all have a regular price, please let me know if you need more assistance for it. thanks

#287076

Thank you very much for your assistance 🙂