WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Tweak price display on page

[Resolved] Tweak price display on page

  • 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/

Viewing 15 replies - 1 through 15 (of 22 total)
  • 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…

    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.

    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.

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

    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?

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

    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?

    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}

    amrushp

    @amrushp

    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.

    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.

    amrushp

    @amrushp

    @ancaio

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

    Hi AncaIO,

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

    Thanks in advance!

    @ 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.

    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;

    }

    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]

Viewing 15 replies - 1 through 15 (of 22 total)
  • The topic ‘[Resolved] Tweak price display on page’ is closed to new replies.