How to add notranslate for currency symbols - woocommerce - woocommerce

Does anyone know how to stop Google translate from translating just the currency symbol?
I have installed GTranslate to translate woocommerce site. It translates well - however it also translates the currency symbol from £ to Euro. I have serched and found many of the same answer to prevent the currency symbol from being translated.
It involves wrapping every £ sign with a span like, £ this is impractical, takes too long and may need to be removed at a later date.
I thought I would try via a filter in the functions file as mentioned on the woocommerce website (see below) However, it doesn't work - possibly Google is translating it after the filter?
add_filter('woocommerce_currency_symbol', 'change_existing_currency_symbol', 10, 2);
function change_existing_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case 'AUD': $currency_symbol = 'AUD$'; break;
}
return $currency_symbol;
}
Any help or suggestions woul dbe appreicated, I'm a bit stumped on this one.
Thnaks in advance

Related

Enable woocommerce_cart_calculate_fees in the MiniCart? is it possible?

I have a discount added via woocommerce_cart_calculate_fees.
This doesn't work in the minicart unfortunately and the subtotal isn't really correct in the minicart as a result.
Any idea how I could make it work?
Thank you,
Not a complete answer, just a small start.
I haven't found any answer to do this via a WooCommerce native function. So looks like we would have to do it ourselves. This will add the discounts in the minicart:
add_action('woocommerce_mini_cart_contents', 'addminicart');
function addminicart(){
$fees = WC()->cart;
$fees->calculate_fees();
$feesresult = $fees->get_fees();
foreach ($feesresult as $fee){
echo $fee->name.': '.$fee->amount.'<br />';
}
}
2 problems remain:
modifying the total/subtotal to include these
dealing with cart fragments / caching. I think this is a bit theme dependant. Anyway, this code will clear it via JS: $(document.body).trigger('wc_fragment_refresh');

Buddy Press sort by last name?

I’ve been trying to get a Members Directory to sort by last name, but have had no luck. Any help would be much appreciated.
The directory is here: http://109.199.101.20/~newfeldenkrais/practitioner-search/results/
The search is powered by the plugin BP Profile Search, but is displaying on the default members page.
Versions:
WP – Version 4.7.5
BP – Version 2.8.2
BP Profile Search – Version 4.7.6
I’ve tried various solutions that I was able to find on Google with no luck, the most recent solution I could find was here: https://buddypress.org/support/topic/custom-searchfilter-based-on-custom-field/
It looks like that solution is looking for the space between the First Name and Last Name to target the last name, but BuddyPress seems to be grabbing the “nicename”, which has no space. So, it isn’t able to target the space for me?
Use this hook in functions.php,
public function alphabetize_by_last_name( $bp_user_query ) {
if ( 'alphabetical' == $bp_user_query->query_vars['type'] )
$bp_user_query->uid_clauses['orderby'] = "ORDER BY substring_index(u.display_name, ' ', -1)";
}
add_action ( 'bp_pre_user_query', 'alphabetize_by_last_name' );
Ref : https://gist.github.com/mgmartel/4463855
https://buddypress.org/support/topic/sort-user-list-by-last-name/

wordpress - translating woocommerece menu

I am using the woocommerece plugin and I uploaded the hebrew translation. Everything work well and the extra translation I needed I did with the loco plug in. There is 1 word that stayed in english in the my account menu "addresses" and i don't know why it stayed there and canwt find it in the pot file to translate it. Does anyone has some idea for it?
I solved the problem with a code snippest I found in http://www.remicorson.com/.
The snippest show you how to translate a single word, I used it with the problematic word, and it worked!
// Translating single words
add_filter('gettext', 'translate_text');
add_filter('ngettext', 'translate_text');
function translate_text($translated) {
$translated = str_ireplace('ADDRESSES', 'כתובות', $translated);
return $translated;
}

Wordpress WPML not translating get_option

i am trying to translate my plugin options through WPML but it is not working.
Here is how i have placed my string in the plugin file
get_option(_e('my_label','my-text-domain'));
I have already scan my plugin through the WPML and have done translation in "German" while default is English.
Can anyone help me.
Thanks
The issue is that _e outputs the translated text.
You want __ (double underscore), which will return the translated text.
I would explore other solutions to this problem. In general you shouldn't be using translation to determine what option to pull from the database. The functionality of your plugin should not hinge on whether or not the translated text is a valid option name.
An alternative approach may be to use get_locale to fetch the current locale and then use that to determine the option name:
$option_name = get_locale() . 'my_label';
$label = get_option( $option_name );
Now you can still get the localized version of your option, without depending on translators to input the correct option name.
If you have to use the translation approach, I would use _x to explain that the translated text should be an option key.
get_option( _x('my_label', 'Must be a valid option name', 'my-text-domain') );
Provided that you have multiple entries in your meta table per language, try the double underscore function?:
get_option( __( 'my_label','my-text-domain' ) );

Do WordPress widget (or sidebar) hooks exist?

I'm trying to filter ALL widget output through a simple filter, but can't find any hooks and was hoping to be pointed in the right direction. Or possibly my efforts are not even possible?
My simple filter is something like this:
function clean_widget_output( $input ) {
return str_replace( array( "\t", "\n", "\r" ), '', $input );
}
add_[FILTER OR ACTION]( 'need_a_hook', 'clean_widget_output', 99 );
Any ideas? I'm pretty new to PHP, but I can get around.
This was borne out of the need/desire to clean the god-awful HTML spewed by WordPress' widgets. I love what they do, but some of the output makes me cry.
The short answer is output buffering because I couldn't find any widget or sidebar hooks.
The long answer is:
function tidy_sidebar( $sidebar_name_or_id )
{
ob_start();
$bool = dynamic_sidebar( $sidebar_name_or_id);
if ( $bool )
{
$str = ob_get_contents();
$str = 'do cleanup stuff...';
}
else
{
$str = '';
}
ob_end_clean();
return $str;
}
Then call echo tidy_sidebar( 'sidebar-name-or-id' ); from your theme.
I had a similar issue and after looking through Adam Brown's list of all WordPress filter hooks, found that the hook I needed does exist (widget_title, as pxl mentions), but that there is no hook to get all widget output. I thought I'd elaborate on the solution that worked for me.
Theoretically, the widget_title hook should affect all widgets on your blog, but I'm sure some 3rd party widgets neglect to include the necessary line of code to apply any title filters, so it's not foolproof. It worked for me, however, and it can be used to apply custom 'shortcode' (more accurately, in this case, 'longcode') or syntaxes to your widget titles. For example, I wanted to occasionally include html code in my widget titles, but by default, all html is stripped out. So, in order to be able to add things like <em> tags to text in some of my titles, I chose a custom syntax: [[ instead of < & ]] instead of > (for ex, [[em]] and [[/em]]) and then created a function in my theme's functions.php file to process that custom syntax and replace it with the html equivalent:
function parse_html_widget_title( $text ) {
return str_replace(array('[[', ']]'), array('<', '>'), $text);
}
Then I added a line below it to add the function as a filter:
add_filter('widget_title', 'parse_html_widget_title', 11); // 11 is one above the default priority of 10, meaning it will occur after any other default widget_title filters
The add_filter / apply_filter functionality automatically passes the content being filtered as the first parameter to the function specified as the filter, so that's all you need to do.
In order to do something similar for the main output of the widget, you would need to look at all your widgets to see what hook they use and verify that they have a filter for their main output, than use add_filter() for each hook you find with your custom callback function (for example, it's widget_text for the Text widget output, or get_search_form for the search form [you can see it in wp-includes/general-template.php, at the get_search_form() function]). The problem is that some of the dynamically generated widgets don't have hooks (like the Meta widget), which is why the output buffering solution Jeff provides is the most versatile, though not ideal, solution.
there are lots of hooks for wordpress widgets that aren't documented. The wordpress codex doesn't list them, for whichever reason (such as these hooks may change in the future and will break unexpectedly with new updates and versions)... so use these with extreme caution.
to find out what they are, there are at least 2 places to look:
<wordpress install directory>/wp-includes/default-filters.php
<wordpress install directory>/wp-includes/default-widgets.php
contained in those two files is a pretty good listing of all the hooks wordpress uses.
An example would be a filter for widgets is widget_title
again, use these with caution, they're not guaranteed to work past the specific version of the code you're looking at.
I'm not sure when they introduced the widget_text filter, maybe they didn't have it in '09 when this question was originally asked, but since it's there now, and for the sake of anyone that gets this stackoverflow like I did from google and just happens to read far enough down to see this answer, it's now actually quite simple:
function my_widget_filter( $content )
{
// manipulate $content as you see fit
return $content;
}
add_filter( 'widget_text', 'my_widget_filter', 99 );
Also maybe check out the dynamic_sidebar_params filter --
Another link --

Resources