How to translate a string in Woocommerce single language website - woocommerce

I need to translate __( 'privacy policy', 'woocommerce' ) which can be found in Woocomerce/includes/wp-template-functions.php. Full code for this is here
$privacy_link = $privacy_page_id ? '' . __( 'privacy policy', 'woocommerce' ) . '' : __( 'privacy policy', 'woocommerce' );
This is included inside textarea in Woocommerce->settings->Account and privacy, looks like a shortcode
Ukoliko ste pročitali i razumijeli naša [privacy_policy] molimo Vas da...
This is actually translated in Croatian language but I would need to change words slightly, how can I do it? Website is single language and I am not able to translate it with Gettext like I did some other strings
function my_text_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'privacy policy' :
$translated_text = __( 'pravila privatnosti', 'woocommerce' );
break;
}
return $translated_text;
}
add_filter( 'gettext', 'my_text_strings', 200, 3 );

Try Loco Translate plug-in (if you're using WordPress). It allows you to translate a lot of things down to the very detail. You can find the plug-in here.

Related

Need to Change Sale Badge Text in WooCommerce

The following works for the Product page but it does not work for the Shop page.
<?php
add_filter('woocommerce_sale_flash', 'woocommerce_custom_sale_text', 10, 3);
function woocommerce_custom_sale_text($text, $post, $_product)
{
return '<span class="onsale">PUT YOUR TEXT</span>';
}
Please suggest modifications.
Thanks!
Use This
add_filter( 'woocommerce_sale_flash', 'wooc_custom_replace_sale_text' );
function wooc_custom_replace_sale_text( $html ) {
return str_replace( __( 'Sale!', 'woocommerce' ), __( 'Your Text', 'woocommerce' ), $html );
}
I tried your code and it works perfectly for the shop page as well. You may try increasing the priority or it can be a conflict with some other plugin or theme.
You may also check the following file to confirm it has applied the woocommerce_sale_flash filter
woocommerce\templates\loop\sale-flash.php

Wordpress - Get current language on functions.php

I have the following code added on my theme's functions.php file, in order to translate some rebel strings I was unable to translate by the ordinary way / plugins:
function wc_billing_field_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Billing Address' :
$translated_text = __( 'Detalles de facturación', 'woocommerce' );
break;
case 'Shipping Address' :
$translated_text = __( 'Dirección de envío', 'woocommerce' );
break;
}
return $translated_text;
}
add_filter( 'gettext', 'wc_billing_field_strings', 20, 3 );
Now I have installed WPML and I need this code to run only when the languaje is Spanish.
ICL_LANGUAGE_CODE contain current language https://wpml.org/documentation/support/wpml-coding-api/
But, if you already using WPML — why you don't get rid of this code at all and translate all string inside WPML admin?

Change wording on Woocommerce Checkout page

Thanks to help here:
Change Billing details text to Shipping details
I could change Billing details text on Woocommerce Checkout page by adding this to functions.php in Child theme:
function wc_billing_field_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Billing details' :
$translated_text = __( 'Billing Info', 'woocommerce' );
break;
}
return $translated_text;
}
add_filter( 'gettext', 'wc_billing_field_strings', 20, 3 );
What are the codes to change these 3 additional texts with different wording:
Additional information, PRODUCT & QUANTITY
(see screenshot):
Woocommerce Checkout Page
It would be better to override the checkout/form-checkout.php and checkout/review-order.php
Or You can use gettext filter .
This filter hook is applied to the translated text by the
internationalization functions (__(), _e(), etc.)
function th_wc_order_review_strings( $translated_text, $text, $domain ) {
if(is_checkout()){
switch ($translated_text) {
case 'Billing details' :
$translated_text = __( 'Billing Info', 'woocommerce' );
break;
case 'Additional information':
$translated_text = __('New Field Name', 'woocommerce');
break;
case 'Your order':
$translated_text = __('My Order', 'woocommerce');
break;
case 'Product':
$translated_text = __('Your Product', 'woocommerce');
break;
}
}
return $translated_text;
}
add_filter( 'gettext', 'th_wc_order_review_strings', 20, 3 );
Try changing the above code to your requirements.

Customize no result page

I have a problem with no result page. I have a search box, if you find something then u can see "Search result : ", but if u didnt find then u can see "No Search result : ". I want to remove this NO before search result, but I dont find any solution for this. I tried already many different functions and css, but nothing .. I want to remove this NO, or whole this line (No search result : ).
This is what I have atm in functions.php
add_filter( 'tc_search_results_title' , 'my_search_results_title');
function my_search_results_title(){
$my_search_results_title = __('Search result :', 'customizr-child');
return $my_search_results_title;
}
add_filter('tc_breadcrumb_trail_items', 'search_results_breadcrumb');
function search_results_breadcrumb( $trail ){
if ( ! is_search() )
return $trail;
$_last = sizeof($trail) - 1;
$_search_string = __('Search result: ', 'customizr-child');
/* or you an use the function used for that other snippet to have the same title, in this case remove the comment of the line below */
// $_search_string = my_search_results_title();
if ( is_paged() )
$trail[$_last] = '' . sprintf( '%2$s "%1$s"' , esc_attr( get_search_query() ), $_search_string ) . '';
else
$trail[$_last] = sprintf( '%2$s "%1$s"', esc_attr( get_search_query() ), $_search_string );
return $trail;
}
add_filter( 'tc_no_result_content', 'my_no_result_content');
function my_no_result_content() {
return '<div class="tc-content span12"><h1>Didnt find anything, try again</h1></div>';
}
I use Customizr child theme in Wordpress
Maybe somebody can help me with this.
Thanks !
You're using the wrong filter. You'll have to use tc_search_results_header_content instead and replace the No string. You can also use to original part of code and remove the unwanted part, something like:
function my_search_results_header_content ($content) {
return sprintf( '<div class="row-fluid"><div class="%1$s"><h1 class="%2$s">%3$s%4$s %5$s </h1></div><div class="%6$s">%7$s</div></div>',
apply_filters( 'tc_search_result_header_title_class', 'span8' ),
apply_filters( 'tc_archive_icon', 'format-icon' ),
'', // Original uses: have_posts() ? '' : __( 'No' , 'customizr' ).' ' ,
apply_filters( 'tc_search_results_title' , __( 'Search Results for :' , 'customizr' ) ),
'<span>' . get_search_query() . '</span>',
apply_filters( 'tc_search_result_header_form_class', 'span4' ),
have_posts() ? get_search_form(false) : ''
);
}
add_filter('tc_search_results_header_content', 'my_search_results_header_content');
Hope it helps.

Problems adding action links to WordPress plugin?

I'm trying to add some action links to a WordPress plugin. I started with the following.
class Angelleye_PayPal_WooCommerce
{
public function __construct()
{
add_filter('plugin_action_links', array($this,'plugin_action_links'));
}
public function plugin_action_links($actions)
{
$custom_actions = array(
'configure' => sprintf( '%s', admin_url( 'admin.php?page=wc-settings&tab=checkout' ), __( 'Configure', 'paypal-for-woocommerce' ) ),
'docs' => sprintf( '%s', 'http://docs.angelleye.com/paypal-for-woocommerce/', __( 'Docs', 'paypal-for-woocommerce' ) ),
'support' => sprintf( '%s', 'http://www.angelleye.com/contact-us/', __( 'Support', 'paypal-for-woocommerce' ) ),
'review' => sprintf( '%s', 'http://wordpress.org/support/view/plugin-reviews/paypal-for-woocommerce', __( 'Write a Review', 'paypal-for-woocommerce' ) ),
);
// add the links to the front of the actions list
return array_merge( $custom_actions, $actions );
}
}
This works except that it puts the links on every single plugin that's currently enabled instead of just my own. I'm looking at the WordPress codex info about this, and it shows to use the filename appended to the filter name. So I made the adjustment like this:
add_filter('plugin_action_links_'.__FILE__, array($this,'plugin_action_links'));
When I do that, though, all of the links go away altogether and they don't show up anywhere, not even my own. What am I doing wrong here?
As explained by Akshay, we need to use the plugin_basename as suffix for the hook. But for completeness, a couple of missing details.
The hook can also take a prefix to show the action links in the Network screen of a Multisite installation:
$basename = plugin_basename( __FILE__ );
$prefix = is_network_admin() ? 'network_admin_' : '';
add_filter(
"{$prefix}plugin_action_links_$basename",
array( $this,'plugin_action_links' ),
10, // priority
4 // parameters
);
The hook takes 4 parameters, which may contain useful information for building the links:
public function plugin_action_links( $actions, $plugin_file, $plugin_data, $context )
{
// $plugin_file is the plugin_basename
// $plugin_data contains the plugin's header information
// $context is the current screen (all: All plugins, active: Active plugins)
}
If we use the hook without the basename suffix, we can use the $plugin_file param to filter out only our plugin(s).
Use plugin_basename( __FILE__ ) instead of __FILE__.
Use following filter to add action links.
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), array($this, 'plugin_action_links') );
I had working this filter in one of my plugin, hope its work for you too.
use &$this instead of $this,
add_filter('plugin_action_links_' . $this->plugin_file, array(&$this, 'settings_links'), 10, 1);

Resources