-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Use the price decimal separator to format product weight and dimensions #32746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use the price decimal separator to format product weight and dimensions #32746
Conversation
|
Hi @Konamiman, thanks for merging this pull request. Please take a look at these follow-up tasks you may need to perform:
|
|
I need to reset the separator (.) For the size in the backend without changing the decimal separator on the frontend (,). How can I do? |
imagocreative
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to reset the separator (.) For the size in the backend without changing the decimal separator on the frontend (,). How can I do?
|
Hi @imagocreative, I think you could use the |
I've seen this before but can't figure out how to make it work |
|
Here's a possible way to use it. Assume you have configured the decimal separator as add_filter( 'formatted_woocommerce_price', function( $formatted_price, $price, $decimals, $decimal_separator ) {
if( !is_admin() ) {
$formatted_price = str_replace( $decimal_separator, ',', $formatted_price );
}
return $formatted_price;
}, 10, 4 );You can add this code by using the code snippets plugin. |
The problem with this code is that the thousands separator also changes. |
|
@imagocreative Hum... so you need to replace only the last occurrence of the separator. What about this then: add_filter( 'formatted_woocommerce_price', function( $formatted_price, $price, $decimals, $decimal_separator ) {
if( !is_admin() ) {
$pos = strrpos( $formatted_price, $decimal_separator );
if($pos !== false) {
$formatted_price = substr_replace( $formatted_price, ',', $pos, strlen($decimal_separator) );
}
}
return $formatted_price;
}, 10, 4 ); |
All Submissions:
Changes proposed in this Pull Request:
This PR link the price decimal separator to the product weight and dimensions decimal separator. Since a decimal separator is used to separate an integer, no matter if this is used for a price, weight, dimension, etc., it has sense to have a consistence in the whole site using this, settings for weight and dimensions too.
If, for some reason, a user would need to use different decimal separators for prices and weight/dimensions in the admin dashboard or front-end, they can use the following filter hooks:
woocommerce_format_localized_decimalwoocommerce_format_weightwoocommerce_format_dimensionsPlease note that this only modify the display, not the storage of the data that remains using the dot (.) as decimal separator.
This change will benefit many users, considering that most countries use a comma as decimal separator than a dot.
Closes #25864.
How to test the changes in this Pull Request:
Other information: