WordPress.org

Forums

WooCommerce - excelling eCommerce
[resolved] Tweak price display on page (23 posts)

  1. eventkonsulterna
    Member
    Posted 1 year ago #

    Hi guys!
    I just updated to the latest woocommerce version and now all products show the lowest to highest price (variable products) on the product page and in category list.

    Before it only showed the lowest price like I wanted it to.
    Can anyone help to get it back that way?

    This line that makes it: woocommerce/templates/single-product/price.php
    <p class="price"><?php echo $product->get_price_html(); ?></p>

    That now looks like [low] - [high] and I want it to just show the low price. Thank you

    https://wordpress.org/plugins/woocommerce/

  2. Feddman
    Member
    Posted 1 year ago #

    I have the same issue. For the time being, I've made a little css tweak to get things back to how it previously showed.

    .price .amount:nth-of-type(2) {
      display: none;
    }
    
    .price {
      color: rgba(0,0,0,0.0);
    }

    First block selects the second amount span (which is the one with highest price value and displays it to none

    Second block just makes the little dash in between transparent, so it doesn't show. (haven't come up with a more clever solution to hide text which is not in between tags just yet...)

    It might be a bit of a dirty solution, but works for the time being. I sure hope someone comes up with a more elegant solution...

  3. AncaIO
    Member
    Posted 1 year ago #

    Hi there.

    There are two snippets you can start from here, depending on whether you have sale prices or just regulars (untested): https://gist.github.com/angryoaf/5380297

    For regular price variations, I use this and it worked great for me:

    add_filter('woocommerce_variable_price_html', 'custom_variation_price', 10, 2);
    
    function custom_variation_price( $price, $product ) {
    
    	$price = '';
    
    	if ( !$product->min_variation_price || $product->min_variation_price !== $product->max_variation_price ) {
    		$price .= '<span class="from">' . _x('From', 'min_price', 'woocommerce') . ' </span>';
    		$price .= woocommerce_price($product->get_price());
    	}
    
    	return $price;
    }

    Let me know if it worked for you or if you require further assistance with this.

  4. Coen Jacobs
    Member
    Posted 1 year ago #

    We have added a workaround for this to our list of common issues (with a similar script as posted above): Revert variation price ranges back to the WooCommerce 2.0 format.

  5. eventkonsulterna
    Member
    Posted 1 year ago #

    The workaround works great! Thank you all for your fast help!

  6. queenb123
    Member
    Posted 10 months ago #

    This does not work for me i am getting a syntax error can anyone help me please, i am not good at coding, i have copied and pasted the above code into my functions.php (not the child theme tried that and it did not work),i really need help what do i do please?

  7. AzherJawed
    Member
    Posted 10 months ago #

    Thank AncaIO its work for me.
    Have a great job! :)

  8. Morgan Feeney
    Member
    Posted 10 months ago #

    Coen, many thanks for the fix, however the VAT price suffix does not display after applying it. Should there be an extra line or 2 to accommodate for this?

  9. lorro
    Member
    Posted 10 months ago #

    Try this css fix:

    .woocommerce ul.products li.product .price,
    .woocommerce-page ul.products li.product .price
    {visibility:hidden}
    .woocommerce ul.products li.product .price span,
    .woocommerce-page ul.products li.product .price span
    {display:none}
    .woocommerce ul.products li.product .price span:first-child,
    .woocommerce-page ul.products li.product .price span:first-child
    {display:inline; visibility:visible}
    .woocommerce ul.products li.product .price woocommerce-price-suffix,
    .woocommerce-page ul.products li.product .price .woocommerce-price-suffix
    {visibility:visible}
  10. amrushp
    Member
    Posted 9 months ago #

    The code from AncalO works great. All my variable products show the lowest price.

    But now it is showing "From" and it has the lowest price. Is it possible to remove that as well and simply show the price value?

    Also when I change the variation, It doesn't change the main price value and it continues to show the lowest value. The price of that particular variation just shows up much smaller below but the main price value continues to show the original From: and the lowest price value.

  11. AncaIO
    Member
    Posted 9 months ago #

    Hi,
    @AzherJawed: You're welcome!

    @amrushp:
    For your first issue, try removing the "from"-related stuff in the snippet above. Maybe something like this (untested):

    add_filter('woocommerce_variable_price_html', 'custom_variation_price', 10, 2);
    
    function custom_variation_price( $price, $product ) {
    
    	$price = '';
    
    	if ( !$product->min_variation_price || $product->min_variation_price !== $product->max_variation_price ) {
    		$price .= '<span class="not-from">' . _x('', 'min_price', 'woocommerce') . ' </span>';
    		$price .= woocommerce_price($product->get_price());
    	}
    
    	return $price;
    }

    As for the second issue, I can't help you. I have not touched WooCommerce in a few months, but I am guessing you need some conditionals in there. Maybe someone with some recent WooCommerce interaction can point you in the right direction.

    Let me know if you got rid of that nasty "from" and best of luck with the rest.

  12. amrushp
    Member
    Posted 9 months ago #

    @AncaIO

    Thank you so much for the quick reply! The code works exactly how I wanted. :) The second issue was not a major one.:)

  13. bewa
    Member
    Posted 9 months ago #

    Hi AncaIO,

    i have the same problem but where will i put this code?

    Thanks in advance!

  14. AncaIO
    Member
    Posted 9 months ago #

    @ bewa: Hi,

    Sorry for the late reply, I've been swamped by other concerns. From your question, I am assuming you have no WP programming experience. If I am wrong, don't take my answer the wrong way :)

    You should put this code in your theme's functions.php file.

    However, be careful with it, the smallest error can bring down your site.

    Before putting any new code in it, make a site backup, so that you can restore your site to the previous state if anything goes wrong or download the functions.php via FTP (if you have access to it). If you make a backup, make sure the backup includes your files not just your database. Please note, that if you make a mistake in functions.php it can make your site inaccessible in both front end and admin, so without FTP access or some other form of access to your wordpress and theme files, you will probably not be able to correct the mistake.

    If the instructions above are not something you are familiar with, than it's probably best you don't do it yourself and hire someone with more experience to help you out.

    Let me know how it went for you.

  15. queenb123
    Member
    Posted 7 months ago #

    i am relatively new to WP and have had a problem for days now, i am building a site with lots of price variations, but the annoying thing is i have managed to show only the lowest price on the shop pages, but on the product pages the lowest price still shows, and this is before the customer has chosen their variations, i would like to remove the lowest price on the product pages as it is very confusing for customers, i only want them to see a price once they have made their selection, i had a developer work on this but they are not available, here is the code i used to remove the price variations on the shop pages:

    add_filter('woocommerce_variable_sale_price_html','nyasro_price_fix',10,2); add_filter('woocommerce_variable_price_html','nyasro_price_fix',10,2); function nyasro_price_fix( $price, $woo ) { $price = ''.get_woocommerce_currency_symbol().$woo->get_variation_price().''; return $price;

    }

  16. queenb123
    Member
    Posted 7 months ago #

    please see images here:

    [url=http://postimg.org/image/4nl6tw673/][img]http://s3.postimg.org/4nl6tw673/hair_1.png[/img][/url]

    [url=http://postimg.org/image/k7skkfgbj/][img]http://s3.postimg.org/k7skkfgbj/hair_2.png[/img][/url]

  17. JosephK77
    Member
    Posted 7 months ago #

    I am experiencing an issue close to this before the most recent updates to woocommerce no pricing would show until the variation was selected, after selected the appropriate price for that variation would show example: http://www.thescriptco.com/product/1930-beauty-sample-script/

    I dont want price range to show at all, and I just want the right price to show by variation when it is selected, now you dont even know what the price is for the variation selected until you get to the cart page.

    Thoughts?

  18. aartvarktees
    Member
    Posted 7 months ago #

    @Coen Jacobs

    I followed your link and used stevenTieulie's revision of the snippet (so "From:" is not displayed either). I pasted it into my theme's functions.php. As soon as I save it, my screen went blank. I can't even get to my wordpress log-in page. This is the message I'm getting:

    Parse error: syntax error, unexpected '<' in /home/wp_brx9va/aartvarktees.com/wp-content/themes/goodstore/functions.php on line 951

    I clicked page back on my browser, deleted the snippet, and re-saved, but it didn't work. I can't access my site!

    Can you or anyone else help me out with a fix? I am relatively new to building websites and know nothing about coding.

  19. lorro
    Member
    Posted 7 months ago #

    You'll need to access your files using FTP or your host's file manager software.

    Navigate to:
    /wp-content/themes/goodstore/functions.php
    Edit it in a plain text editor, not MS Word. Try putting the snippet back in, but this time omit the first line "<?php", this is an error if there is one of these a bit higher up in the file.

  20. aartvarktees
    Member
    Posted 7 months ago #

    @lorro

    Thank you for the quick response! I was successfully able to do this and it worked!

  21. CARRIEYEO
    Member
    Posted 7 months ago #

    Hey guys...

    What if I only have 2 variations and I would like to display my price as $price1 / $price2.
    Essentially replacing a dash with a slash.

    Any ideas?

    Thank you in advance!

  22. lorro
    Member
    Posted 6 months ago #

    @CARRIEYEO
    What you are seeing as a dash is the "from-to" string, which, in English, is translated into a dash. You can translate "from-to" into a slash or something else using a custom translation. Search for "WooCommerce localisation".

  23. crashguru
    Member
    Posted 5 months ago #

    Thank you very much @AncaIO !!
    Just a little hint - if you add a colon as in 'From:' the WooCommerce translations are also working.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WooCommerce - excelling eCommerce
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic