The prices in my woocommerce store have the words "starting from" automatically added in front of them and I want to remove these words.
This happens on all products both variable and regular products. I need a code that will allow me to completely remove the words that come before the price.
screen shots:
screen shot - regular product
screen shot - variable product
Thanks.
To remove "starting from" prefix from displayed prices, try the following code in function.php file of your active child theme (or active theme).
add_filter( 'woocommerce_get_price_html', 'filter_get_price_html_callback', 10, 2 );
function filter_get_price_html_callback( $price, $product ) {
return str_replace( __('starting from'), '', $price );
}
Similarly for single product pages:
add_filter( 'woocommerce_get_price_html', 'filter_get_price_html_callback', 10, 2 );
function filter_get_price_html_callback( $price, $product ) {
if ( is_product() )
$price = str_replace( __('starting from'), '', $price );
return $price;
}
Note: Please replace 'starting from' according to your need.
Related
I'm customizing Woocommerce plugin, trying to remove decimals from product variation prices in product detail page.
Ex- if someone select option i want to display the regular and sales prices without decimals and the other locations of site like shop, cart, checkout no need to change.
I found this filter but it change prices of whole site.
add_filter( 'woocommerce_price_trim_zeros', '__return_true' );
https://snipboard.io/GXgtUi.jpg
anyone have idea or solution about archive this, Thanks a lot
You can try below code snippet into your theme function.php file
add_filter( 'formatted_woocommerce_price', 'ums_remove_zero_decimals', 10, 5 );
function ums_remove_zero_decimals( $formatted_price, $price, $decimal_places, $decimal_separator, $thousand_separator ) {
$product_id = get_the_ID();
$product = wc_get_product( $product_id );
if( is_single()) {
if($product->is_type( 'variable' )) {
return (int) round( $price );
}
else {
return ( $formatted_price);
}
}
}
Let me know if this works for you or not.
I have a WooCommerce store and am using the 'Advanced Dynamic Pricing for Woocommerce' plugin. I need to use this plugin because I have discount structures set up
Percentage discounts have been applied to all products in store. The original price is crossed out with the new price next to it.
enter image description here
I want to display a suffix next to the new price that says 'inc VAT' to indicate that the price is inclusive of VAT.
I have tried this code which seems to work on products that don't have discounts applied but not on discounted products.
add_filter( 'woocommerce_get_price_html', 'custom_price_suffix', 100, 2 );
function custom_price_suffix( $price, $product ){
$price = $price . 'inc VAT' ;
return apply_filters( 'woocommerce_get_price', $price );}
Anyone know how I can achieve this?
The generated HTML code looks like this:
<div class="woosg-price">
<div class="woosg-price-ori">
<del>
<span class="woocommerce-Price-amount amount">
<span class="woocommerce-Price-currencySymbol">£</span>262.00</span>
</del>
<ins><span class="woocommerce-Price-amount amount"><span class="woocommerce-Price-
currencySymbol">£</span>117.90</span></ins>
</div>
<div class="woosg-price-new"></div>
</div>
You can use woocommerce_get_price_suffix dedicated hook, targeting on sale products like:
add_filter( 'woocommerce_get_price_suffix', 'custom_price_suffix', 999, 4 );
function custom_price_suffix( $html, $product, $price, $qty ){
if ( $product->is_on_sale() ) {
return ' ' . __('inc VAT', 'woocommerce');
}
return $html;
}
or maybe this instead (because of Advanced Dynamic Pricing for Woocommerce plugin):
add_filter( 'woocommerce_get_price_html', 'custom_price_suffix', 999, 2 );
function custom_price_suffix( $price_html, $product ){
if ( $product->is_on_sale() ) {
$price_html .= ' ' . __('inc VAT', 'woocommerce');
}
return $price_html;
}
Code goes in functions.php file of the active child theme (or active theme). Tested and works.
Related:
Show Price Suffix only on all WooCommerce Product loops
Show a price suffix only on all WooCommerce single products
You Can add Suffix using the below filter.
add_filter( 'woocommerce_get_price_suffix', 'swt_add_price_suffix', 99, 4 );
function swt_add_price_suffix( $html, $product, $price, $qty ){
$html .= ' inc VAT';
return $html;
}
Or You can use below code as well.
add_filter( 'woocommerce_get_price_html', 'swt_add_price_suffix', 99, 2 );
function swt_add_price_suffix( $price, $product ){
$price = $price.' inc VAT';
return $price;
}
You can add suffix from the WooCommerce settings using the below steps.
Goto WooCommerce -> Settings -> General.
Mark checked "Enable tax rates and calculations" checkbox.
Open the Tax Tab.
Add the suffix text in "Price display suffix" text field.
Save the settings.
I thought this would have been easy, but I am stuck. All I am trying to do is add the word each after the variation price on a product page. The solution I have found adds it on the category page and in two places on the product page.
The code is:
/* Adds a text Each - after price */
function change_product_price( $price ) {
$price .= ' each';
return $price;
}
add_filter( 'woocommerce_get_price_html', 'change_product_price' );
From the picture above, I only need the each added to the price above the add to cart button, but not the other pacles like the crossed out section in the photo above.
Thank you for any guidance you can provide.
The following code will add a suffix to the product variations price:
add_filter('woocommerce_available_variation', 'variation_price_custom_suffix', 10, 3 );
function variation_price_custom_suffix( $variation_data, $product, $variation ) {
$variation_data['price_html'] .= ' <span class="price-suffix">' . __("each", "woocommerce") . '</span>';
return $variation_data;
}
Code goes in function.php file of your active child theme (active theme). Tested and works.
I am working on salient theme for my E-commerce website. I want to show "B" after price in woocommerce product page.
The page displays like "$99,99"
I want to make it displays like this: "$99,99 TEXT"
I have the code for it :
function change_product_price( $price ) {
$price .= ' TEXT';
return $price;
}
add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' );
add_filter( 'woocommerce_cart_item_price', 'cw_change_product_price_display' );
Now I want to know where to add the code in woo-commerce directory. Any help would be appreciated.
thanks
Add this code inside functions.php of your theme:
function cw_change_product_price_display( $price ) {
$price .= ' TEXT';
return $price;
}
add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' );
add_filter( 'woocommerce_cart_item_price', 'cw_change_product_price_display' );
The name of the function you're calling in add_filter isn't the same as the name of your actual function. It seems you've forgotten the _display in the function name.
In the following code, the function is name cw_change_product_price_display and cw_change_product_price_display is called in add_filter
function cw_change_product_price_display( $price ) {
$price .= ' TEXT';
return $price;
}
add_filter( 'woocommerce_get_price_html', 'cw_change_product_price_display' );
add_filter( 'woocommerce_cart_item_price', 'cw_change_product_price_display' );
Tested for woocommerce 6.x.x - 2022
IMPORTANT: If you have enabled the tax calculation (woocommerce -> Settings -> Enable Tax) inside woocommerce, you have the option from the admin panel to add whatever you want after the price (suffix). This option can be found inside the Admin dashboard and under the woocommerce -> Settings -> Tax.
The code snippets provided below can be added inside the file functions.php of your child's theme folder. I would strongly recommend you to use a child theme (if provided by the theme or create one) so that when you will update your theme, none of these changes will get erased.
Woocommerce provides a filter, for quite some time now, that you can add a price suffix, and that's what you want in your case.
add_filter( 'woocommerce_get_price_suffix', 'add_some_text_after_price', 99, 4 );
function add_some_text_after_price ($html, $product, $price, $qty){
$html .= ' TEXT'; //You can write whatever you want here. Just stay inside the ' '
return $html;
}
Also, as the other answers suggested, the function's name that is inside your filter is not the same as the function's name that you do your action.
The name of your function: change_product_price
And inside your filters that you want to add this action, you call: cw_change_product_price_display
So nothing will happen and nothing will work, like the function, you call I nowhere to be found.
Also except for adding a suffix, you can also add a prefix using one of the filters that you already use (in case someone needs something like that)
add_filter( 'woocommerce_get_price_html', 'my_function', 99, 2 );)
function my_function( $price, $product ){
$price = 'Text ' . $price;
return $price;
}
General Knowledge
The 99 inside the filters is the priority number that the filter will start, before any other filter. That means that if you want to start some filters before others, then you can change the priority. The second number is the number of the arguments ($price, $html, ...) that you put inside your function.
Both numbers are needed in most cases.
I need to change the price of my products in my store, with a 10% discount, if my customer is from some specific place, so, I wrote this code:
add_filter('woocommerce_price_html', 'my_price_edit');
function my_price_edit() {
$product = new WC_Product( get_the_ID() );
$price = $product->price;
echo $price * 0.9;
}
Ok, it works! But when in the checkout the price are normals without the 10% discount!
Does have some hook for change the price of the products in the checkout area or some different code to change correctly in the both (in the product page and checkout)?
New in Woocommerce too.
Your question looks really similiar to this one.
Adding Custom price with woocomerce product price in Cart & Checkout
I think you need to use the woocommerce_cart_item_subtotal hook to change the price in the cart directly (not exactly as a parameter)
I made a slightly modification to the code (changed price formula). I think that may help you.
add_filter( 'woocommerce_get_discounted_price', 'calculate_discounted_price', 10, 2 );
// Display the line total price
add_filter( 'woocommerce_cart_item_subtotal', 'display_discounted_price', 10, 2 );
function calculate_discounted_price( $price, $values ) {
// You have all your data on $values;
$price = $price*.09;
return $price;
}
// wc_price => format the price with your own currency
function display_discounted_price( $values, $item ) {
return wc_price( $item[ 'line_total' ] );
}