• Hello, is it possible to translate functions, IDs, for instance

    'title' => __( 'Preventivo', 'woocommerce' ), // TAB TITLE
    echo 'richiesta noleggio volo per ' . $product->get_name(); // TAB TEXT
    echo do_shortcode( '[form id="1046"]' ); // CHANGE SHORTCODE IF SECOND LANGUAGE IS DETECTED

    or custom html and URLs I put in my widget, like

    [button text="torna al catalogo" url="my-language-url"]

    … I guess not, right?

Viewing 15 replies - 1 through 15 (of 48 total)
  • Plugin Author sbouey

    (@sbouey)

    1. title => it’s in the po/mo file you can change it with locotranslate for static text,
    2. product->get_name it can be change directly with Falang i think the filter the_title is used in get_name
    3. do_shorcode falang do nothing on that with the falang pro you can use filter https://www.faboba.com/en/wordpress/falang-for-wordpress/documentation/134-how-to-use-lang-filtering.html .You can use php code to do the same
    4. widget classic ca be translated in Falang > String Translation or you can use a widget by language

    Thread Starter devsaredead

    (@devsaredead)

    I have resolved point 4 easily, but for the function I explained myself wrong. What I need is not just translate the words but trigger the function if the page is in english. So it would be exactly like point 4: having 2 functions and echo the italian/english respectively if the page is in italian or english. I’m not a developer so I wouldn’t even know if it’s possible to do something like that. (the function is one for adding a custom tab to the product page tabs)

    Plugin Author sbouey

    (@sbouey)

    You have to code a little with something like this

    if ( function_exists( 'falang_current_language' ) ) {
    $current_locale = falang_current_language('locale');
    if ($current_locale == 'en_US'){
    //my code for english
    }
    if ($current_locale == 'de_DE'){
    //my code for german
    }

    if you have a lot of language make a switch (use the locale it’s not supposed to change)

    Thread Starter devsaredead

    (@devsaredead)

    …thank you very much indeed for always being so helpful! I have edited my function and I must say that it works! If you would not mind to have a look at the final function, in case you spot any possible errors that could conflict with other things, I’d appreciate:

    /* New Product Tab @ WooCommerce Single Product */

    if ( function_exists( 'falang_current_language' ) ) {
    $current_locale = falang_current_language('locale');

    if ($current_locale == 'it_IT'){
    add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab', 9999 );
    function woo_new_product_tab( $tabs ) {
    $tabs['docs'] = array(
    'title' => __( 'Preventivo', 'woocommerce' ),
    'priority' => 50,
    'callback' => 'woo_new_product_tab_content',
    );
    return $tabs;
    }
    function woo_new_product_tab_content() {
    // The new tab content
    global $product;
    echo 'richiesta noleggio volo per ' . $product->get_name();
    echo do_shortcode( '[forminator_form id="1046"]' );
    }
    }

    if ($current_locale == 'en_US'){
    //my code for english, same as above but with strings translated
    }

    }
    Plugin Author sbouey

    (@sbouey)

    you have to declare $current_locale before or you can have a warning if you disabled Falang

    i use this code but it’s the same

    if (class_exists( 'Falang' )) {

    $current_locale = Falang()->get_current_language()->locale;

    }

    i have update my developper documentation too

    https://www.faboba.com/en/wordpress/falang-for-wordpress/documentation/142-documentation-for-developers.html

    • This reply was modified 1 month, 2 weeks ago by sbouey. Reason: error in code
    • This reply was modified 1 month, 2 weeks ago by sbouey.
    Thread Starter devsaredead

    (@devsaredead)

    Brilliant! Thanks for the tip! Top support ??

    Thread Starter devsaredead

    (@devsaredead)

    …sorry Stéphane, I don’t mean to take advantage of your time but could you help me with a small tweak? I have noticed that the custom tab is added to every products, whereas I wish to have it only for one category. So I think I must add something like

    if( is_product() && has_category( 'Phones' ) )

    but I don’t know where I should insert it in the function we created. ?? I have made some attempts but I failed….

    Plugin Author sbouey

    (@sbouey)

    you can make it after the

    if ( function_exists( 'falang_current_language' ) ) {
    if( is_product() && has_category( 'Phones' ) ) {

    but i haven’t tested category test yet on wc , but i’m actually building a wc site , perhaps i can give you tomorrow more info but use probably more this

    if(has_category(array('category_name_1', 'category_name_2')))
    Thread Starter devsaredead

    (@devsaredead)

    unfortunately it doesn’t work (the tab disappears)

    if (class_exists( 'Falang' ))
    if( is_product() && has_category( 'Phones' ) ) {
    $current_locale = Falang()->get_current_language()->locale;

    I shall hope you will find out more….

    Plugin Author sbouey

    (@sbouey)

    i have found how to make it working perhaps not the right solution but works

    if ( has_term( 'Phones', 'product_cat' ) ) {
    echo 'found';
    }
    Thread Starter devsaredead

    (@devsaredead)

    …I’m not sure it works, or maybe it’s just me who coded it wrong. I have it like this:

    if (class_exists( 'Falang' ))
    if ( has_term( 'Phones', 'product_cat' ) ) {
    echo 'found';
    }

    {
    $current_locale = Falang()->get_current_language()->locale;
    if ($current_locale == 'it_IT'){
    //my code for italian
    }
    if ($current_locale == 'en_US'){
    //my code for english
    }

    and still have the custom tab on all products.

    Plugin Author sbouey

    (@sbouey)

    i give you the code to test if your product is from the phones category

    you want to have the custom tab for just phone in this case it’s something like

    //add code just for Phones category 
    if ( has_term( 'Phones', 'product_cat' ) ) {
    if (class_exists( 'Falang' )) {
    $current_locale = Falang()->get_current_language()->locale;
    if ($current_locale == 'it_IT'){
    //my code for italian
    }
    if ($current_locale == 'en_US'){
    //my code for english
    }
    }
    }

    You can put the code in the woo_new_product_tab function

    Thread Starter devsaredead

    (@devsaredead)

    so it was just some misunderstanding, yes I wish to have the custom tab just for the “phones” category, however it doesn’t work: the custom tabs has disappeared for all categories. But I have noticed that my permalink is structured like this: domain.com/shop-name/product-name/ and my category is domain.com/product_cat/phones/ So maybe we need a different code? Sorry for taking your time…

    Plugin Author sbouey

    (@sbouey)

    it’s easier in this case

    you can do this

    if ( has_term( 'Phones', 'product_cat' ) ) {
    add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab', 9999 );
    }

    or in the woo_new_product_tab you test the Phones term and you exit if it’s not the right one

    Thread Starter devsaredead

    (@devsaredead)

    then I’m doing something wrong, because I still have not the wished result. My current code is:

    if ( has_term( 'noleggio', 'product_cat' ) ) {
    add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab', 9999 );
    }
    if (class_exists( 'Falang' )) {
    $current_locale = Falang()->get_current_language()->locale;
    if ($current_locale == 'it_IT'){
    add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab', 9999 );

    where the last line is repeated. But I have also tried to remove it, with no luck

Viewing 15 replies - 1 through 15 (of 48 total)
  • You must be logged in to reply to this topic.