I am creating an online shop using wordpress and woocommerce and came across the following question:
How can I translate the text in the WooCommerce Cart Sidebar Widget?
I was able to translate some of the text by writing the following code into my functions.php in my child theme:
add_filter('gettext', 'translate_text');
add_filter('ngettext', 'translate_text');
function translate_text($translated) {
$translated = str_ireplace('Text to translate', 'Translation', $translated);
return $translated;
}
Some of the text gets translated using the code above, while other strings are not affected by it. I've noticed that mostly strings within a <span> tag are not translated, although there is one within a <a> tag aswell.
How can I translate the remaining text?
Thanks
I just solved the problem:
All text-elements can be translated by the following code:
add_filter('gettext', 'translate_text');
add_filter('ngettext', 'translate_text');
function translate_text($translated) {
$translated = str_ireplace('Text to translate', 'Translation', $translated);
return $translated;
}
The only thing to notice is that the changes are only visible after you refresh the cart (e.g. by removing all products and adding them again).
Related
I'm using this filter in Wordpress to remove the auto 'p' tags from ACF's text areas:
function acf_wysiwyg_remove_wpautop() {
remove_filter('acf_the_content', 'wpautop' );
}
add_action('acf/init', 'acf_wysiwyg_remove_wpautop');
It's working perfectly fine and removes the wrapping 'p' tag but it's also removing 'br' tags.
How can I keep the 'br' tags so I can still make line breaks in ACF text areas?
Thanks for your help!
You can do this by using the no line to break function:
function acf_wysiwyg_remove_wpautop() {
// remove p tags //
remove_filter('acf_the_content', 'wpautop' );
// add line breaks before all newlines //
add_filter( 'acf_the_content', 'nl2br' );
}
add_action('acf/init', 'acf_wysiwyg_remove_wpautop');
Tested on the latest WordPress with the latest ACF.
I want to change mini "cart" button name to "view Cart" in header widget, i have tried on google but not yet get.
Change WooCommerce "cart" button text for specific tag
Add the following code to your function.php file, and change your specific tag
add_filter('gettext', 'translate_text');
add_filter('ngettext', 'translate_text');
function translate_text($translated) {
$translated = str_ireplace('Order Total', 'New Text Goes Here', $translated);
return $translated;
}
I would like to change the "Order Total:" text on the Thank You (/order/received/) page.
I see that it is in the file /includes/abstracts/abstract-wc-order.php (function get_order_item_totals) but I'm not sure how I can override this file.
I also want to override the "Order Total:" text in the email that the admin receives when someone places an order but I assume that this will also be updated as it's the same content as on the Thank You page.
Does anyone know how to change this text?
Thanks in advance!
1) Add the following text into your functions.php file in your theme. This may not override the text in your email however.
add_filter('gettext', 'translate_text');
add_filter('ngettext', 'translate_text');
function translate_text($translated) {
$translated = str_ireplace('Order Total', 'New Text Goes Here', $translated);
return $translated;
}
2) You can edit the template of the emails by going to wp-content/plugins/woocommerce/templates/emails/. Before editing copy this file and paste it to wp-content/themes/yourthemename/woocommerce/emails/. More information on the template structure can be found here.
hHi all! I have posted this question on the WP support forums, but the community doesn't seem to be as active as stack's, so I am taking a chance here!
I am looking for a plugin that would automatically create a navigation menu (through the use of shortcodes for example) on a long single page documentation page.
The long page is divided into sections. I can imagine using a shortcode at the beginning of every section, and this will create a menu that would be displayed in a sidebar for example (called through a second shortcode perhaps, or a widget)
Any thoughts? Advice?
Thanks!
Use [section]Section Title[/section] shortcodes, then [section_navigation] where you want the navigation links output.
This works, but with a massive caveat -- that [section_navigation] needs to be in your post/page after the other [section] shortcodes... otherwise it generates an empty list.
You should be ok to use it in your theme by putting <?php echo do_shortcode("[section_navigation]");?> in sidebar.php. It will work as long as get_sidebar() is after the_content() in your theme templates (it usually is).
This to go in functions.php
$whit_sections = "";
// [section]My Section Title[/section]
function whit_section_shortcode( $atts, $title = null ) {
// $content is the title you have between your [section] and [/section]
$id = urlencode(strip_tags($title));
// strip_tags removes any formatting (like <em> etc) from the title.
// Then urlencode replaces spaces and so on.
global $whit_sections;
$whit_sections .= '<li>'.$title.'</li>';
return '<span id="'.$id.'">'.$title.'</span>';
}
add_shortcode('section', 'whit_section_shortcode');
// [section_navigation]
function whit_section_navigation_shortcode( $atts, $title = null ) {
global $whit_sections;
return '<ul class="section-navigation">'.$whit_sections.'</ul>';
}
add_shortcode('section_navigation', 'whit_section_navigation_shortcode');
I'm creating a new WP theme and I would like to allow the user to insert a divider in between paragraphs or images he/she is entering, for a post/page.
I want the output to be something like:
<div class="divider"></div>
But I don't want the user to have to enter HTML in the WYSIWYG editor. Is it possible to ask them to enter something like:
<-- break -->
and then translate that to the div markup on display?
Thanks.
Build a function in your theme's functions.php file like this:
function add_div( $content ) {
$content = str_replace( '<!-- break -->', '<div class="divider"></div>', $content );
return $content;
}
then add the following to the theme:
add_filter( "the_content", "add_div" );
The function uses PHP's string replace function to find the text you want your users to input and replace it with the text you want to render, the add_filter() function uses Wordpress's content filter to apply your function to the content of each post after it is read from the database, but before it is rendered to the browser.
This will work in PHP4 and up, which is still the official level of support for Wordpress.