Core and plugin files should never be edited directly, as any updates could overwrite your changes. If you look in WooCommerce source at the get_price_html method, there are a number of filters available to modify the output of the function.
The mechanism behind these variations is called dynamic pricing. It constantly recalculates prices based on predefined variables through different algorithms and store owners can leverage it considering seasonality and user behavior.
However, if you have multiple products with unit prices, this method could be very cumbersome, and I probably do not want to use a switch or an if statement block for every product ID. Instead, I recommend using a product custom field to adjust the price display. I will use the ID to get this field and then save myself from a lot of coding because I will pull the field in programmatically.
If you want to change the pricing display for some products (each product might have a different unit price), a custom field will result in far simpler code, as I can add the field for each product on the list and then simply retrieve this field in the code:
The most important function in the code snippet above is WP_Query, which provides several important functions such as post_type, post_status, posts_per_page, and tax_query. All these functions provide common functionality within the main loop. The get_post_meta() fetches the meta values. the currently selected currency is displayed through the wc_price() function. In the main query, wp_reset_postdata() is used to set the $post global to the current post. Finally, $woocommerce_price_display_cat has the currently selected WooCommerce product category.
In this article, I discussed the issue of changing the price display on WooCommerce product pages. This easy alteration could be done by adding simple code to product page filters. Leave a comment below if you have questions or suggestions about the code or the article.
Owais works as a Marketing Manager at Cloudways (managed hosting platform) where he focuses on growth, demand generation, and strategic partnerships. With more than a decade of experience in digital marketing and B2B, Owais prefers to build systems that help teams achieve their full potential.
It is because we have two payment methods, credit card w/ 12 installments and cash payment. So we need to show the full price, and the discounted price for the cash payment price in all of our price displays.
I used the functions you sent, but the same result happens. The plugin returns the price display to the default price html without my modifications, when a rule is matched in catalog or single product pages.
I need to implement an ecommerce web site developed with woocommerce.
Thanks to our web designer, i need to insert, in archive pages ( categories, up-sell, cross-sell, ecc ), price and title in same container.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
I need to edit the price value for a single product. In single-product/price.php there is a template call to $product->get_price_html. How to edit that function/method to change the way the HTML is presented?
Deleting whole contents of the function located in class-wc-product still displays? why?
You should never edit core and plugin files directly because any updates will overwrite your changes. If you see the WooCommerce source at the get_price_html method, there are many filters available to modify the output of the function.
If you are using one of our themes you can skip this section, this functionality is already built into the framework and can be enabled under Customizer > WooCommerce > Product Catalog > Show the percentage of discount on the sale badge.
In this function we use a regular expression to find and store the opening and closing tags of the sale flash banner, along with its original content. Lines 24 & 25 is where most of the work is done through two helper functions.
Our function here starts by checking the type of the current product. If it encounters a variable or grouped product it calculates and stores the minimum and maximum amounts of money saved and stores it, for the rest of the product types it just calculates the savings from the product sale. The stored values are used to create the string which will be output below the price on the single product view.
The generated string offers the saving_total_price class for styling, you can use it to apply any CSS of your choosing to make the text stand out more. You can even replace it with the woocommerce-notice one to take advantage of built in WooCommerce styling for important information, this is how it would look on our case with the woocommerce-notice class applied.
We have successfully replaced the SALE text in the sale flash badge with the sale percentage for each product and we have made immediately available the amount of money saved on on-sale products to our customers with the help of a child theme and a few lines of code. These simple changes will make sales more appealing to your potential customers and could easily help increase your revenue. If you end up using any of these snippets let us know of your experience with them and the impact they had on your store in the comments below.
Hpw can I display diffrent variant sale percentages? Like I select variation 1 and then ot shows -10% after that I select variation 2 and then it displays -20%. How can this be achieved? Through JQuery? I hope there are other options.
Thanks!