translation of functions ?
-
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 DETECTEDor custom html and URLs I put in my widget, like
[button text="torna al catalogo" url="my-language-url"]
… I guess not, right?
-
you mix the code
- add the product tab filter for the noleggio
- in the code of the woo_new_product_tab add the code depending of Falang and the current language
sorry but not being a dev I don’t understand the logic of “filters” and “if” and “functions”, so I cannot create the right order. Should it first check the category or the language? This is not the right way, is it?
if ($current_locale == 'it_IT')
if ( has_term( 'noleggio', 'product_cat' ) ){
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab', 9999 );but neither this:
if ( has_term( 'noleggio', 'product_cat' ) ) {
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab', 9999 );
if (class_exists( 'Falang' )) {Can the problem be in the URL? Does the function need to see the category slug in the URL? When I have a product page the URL is https://domain/shopname/productname
- This reply was modified 1 month, 1 week ago by devsaredead.
Sorry Stéphane but I tried the whole week and I have not found a solution! Please help me with the right order for if has term / if class exist / current locale / if current locale / add filter because I cannot understand how it works. This is what I got:
if (class_exists( 'Falang' )) {
$current_locale = Falang()->get_current_language()->locale;
if ($current_locale == 'it_IT') { add filter (MY CODE FOR ITALIAN) }if ($current_locale == 'en_US') { add filter (MY CODE FOR ENGLISH) }
}so where do I put
if ( has_term ( 'noleggio', 'product_cat' ) )
andif ( has_term ( 'rents', 'product_cat' ) )
?Working only with a part of the code is not easy , you have to put the whole code you are using
you have put it in function.php ?
You have the url to see the code working ?
Yes I have the following code in my function.php file. This is an example of the product where the custom tab is visible (/product_cat/noleggio/ (Italian) and /product_cat/rents (English)), and this is an example where the tab is visible but I wish it was hidden (all other product_cat).
/* NEW PRODUCT TAB IN WOOCOMMERCE SINGLE PRODUCT */
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 );
function woo_new_product_tab( $tabs ) {
$tabs['docs'] = array(
'title' => ( 'Preventivo', 'woocommerce' ), // TAB TITLE
'priority' => 50, // TAB SORTING (DESC 10, ADD INFO 20, REVIEWS 30)
'callback' => 'woo_new_product_tab_content', // TAB CONTENT CALLBACK
);
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( '[contact form]' );
}
}
if ($current_locale == 'en_US') {
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab', 9999 );
function woo_new_product_tab( $tabs ) {
$tabs['docs'] = array(
'title' => ( 'Quotation', 'woocommerce' ), // TAB TITLE
'priority' => 50, // TAB SORTING (DESC 10, ADD INFO 20, REVIEWS 30)
'callback' => 'woo_new_product_tab_content', // TAB CONTENT CALLBACK
);
return $tabs;
}
function woo_new_product_tab_content() {
// The new tab content
global $product;
echo 'rent request for ' . $product->get_name();
echo do_shortcode( '[contact form]' );
}
}
}/* NEW PRODUCT TAB IN WOOCOMMERCE SINGLE PRODUCT */
function woo_new_product_tab_content() {
// The new tab content
global $product;
echo 'rent request for ' . $product->get_name();
echo do_shortcode( '[contact form]' );
}
function woo_new_product_tab($tabs)
{
if (class_exists('Falang')) {
$current_locale = Falang()->get_current_language()->locale;
if ($current_locale == 'en_US') {
$tabs['docs'] = array(
'title' => ('Quotation', 'woocommerce' ), // TAB TITLE
'priority' => 50, // TAB SORTING (DESC 10, ADD INFO 20, REVIEWS 30)
'callback' => 'woo_new_product_tab_content', // TAB CONTENT CALLBACK
);
}
if ($current_locale == 'it_IT') {
$tabs['docs'] = array(
'title' => ('Preventivo', 'woocommerce' ), // TAB TITLE
'priority' => 50, // TAB SORTING (DESC 10, ADD INFO 20, REVIEWS 30)
'callback' => 'woo_new_product_tab_content', // TAB CONTENT CALLBACK
);
}
}
return $tabs;
}
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab', 9999 );I can’t try it but it should work
I apologize, in the code above I wrote the shortcode [contact form] thinking it was not important to you, but as a matter of fact it’s a different shortcode for the 2 languages (i.e. contactform id=1 and contactform id=2). I can see that it does make a difference, so I do apologize if I have to ask you to adapt the code again (also there was a little error
'title' => ( )
was missing
__(
Besides that, I don’t think it works because I can see the contact form in both product categories
In this case
/* NEW PRODUCT TAB IN WOOCOMMERCE SINGLE PRODUCT */
function woo_new_product_tab($tabs)
{
if (class_exists('Falang')) {
$current_locale = Falang()->get_current_language()->locale;
if ($current_locale == 'en_US') {
$tabs['docs'] = array(
'title' => __('Quotation', 'woocommerce' ), // TAB TITLE
'priority' => 50, // TAB SORTING (DESC 10, ADD INFO 20, REVIEWS 30)
'callback' => 'woo_new_product_tab_content', // TAB CONTENT CALLBACK
);
}
if ($current_locale == 'it_IT') {
$tabs['docs'] = array(
'title' => __('Preventivo', 'woocommerce' ), // TAB TITLE
'priority' => 50, // TAB SORTING (DESC 10, ADD INFO 20, REVIEWS 30)
'callback' => 'woo_new_product_tab_content', // TAB CONTENT CALLBACK
);
}
}
return $tabs;
}
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab', 9999 );I don’t get it. Where does it fetch the $tabs from?
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab', 9999 );
from here $tabs is the parameter but it’s not necessary to add it because it’s only 1 parameter, the 9999 mean you will execute this after other filters
ok it’s 1 parameter but it has 2 echos
function woo_new_product_tab_content() {
// ITALIAN TAB CONTENT
global $product;
echo 'richiesta noleggio volo per ' . $product->get_name();
echo do_shortcode( '[forminator_form id="1046"]' );
}and
function woo_new_product_tab_content() {
// ENGLISH TAB CONTENT
global $product;
echo 'rent request for ' . $product->get_name();
echo do_shortcode( '[forminator_form id="1059"]' );
}change the callback for us
'callback' => 'woo_new_product_tab_content_us'
for it
'callback' => 'woo_new_product_tab_content_it'
with
function woo_new_product_tab_content_it() {
// ITALIAN TAB CONTENT
global $product;
echo 'richiesta noleggio volo per ' . $product->get_name();
echo do_shortcode( '[forminator_form id="1046"]' );
}and
function woo_new_product_tab_content_us() {
// ENGLISH TAB CONTENT
global $product;
echo 'rent request for ' . $product->get_name();
echo do_shortcode( '[forminator_form id="1059"]' );
}sorry I understand the logic but not the syntax, I’m not a PHP dev….
If I substitute the callback it gives me an error, so I have to add it ? but it doesn’t work… sorry for the dum question
'callback' => 'woo_new_product_tab_content', // TAB CONTENT CALLBACK
);
}
function woo_new_product_tab_content_us() {
// ENGLISH TAB CONTENT
global $product;
echo 'rent request for ' . $product->get_name();
echo do_shortcode( '[forminator_form id="1059"]' );
}it’s why i ask for the full php code , work only on part is not enought for you because you are not a dev
you have to use a version of woo_new_product_tab_content by language in your case
pub back all the code here not part of it
sure, thank you for your time. The actual code is this:
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 );
function woo_new_product_tab( $tabs ) {
$tabs['docs'] = array(
'title' => ( 'Preventivo', 'woocommerce' ), // TAB TITLE
'priority' => 50, // TAB SORTING (DESC 10, ADD INFO 20, REVIEWS 30)
'callback' => 'woo_new_product_tab_content', // TAB CONTENT CALLBACK
);
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') {
add_filter( 'woocommerce_product_tabs', 'woo_new_product_tab', 9999 );
function woo_new_product_tab( $tabs ) {
$tabs['docs'] = array(
'title' => ( 'Quotation', 'woocommerce' ), // TAB TITLE
'priority' => 50, // TAB SORTING (DESC 10, ADD INFO 20, REVIEWS 30)
'callback' => 'woo_new_product_tab_content', // TAB CONTENT CALLBACK
);
return $tabs;
}
function woo_new_product_tab_content() {
// The new tab content
global $product;
echo 'rent request for ' . $product->get_name();
echo do_shortcode( '[forminator_form id="1059"]' );
}
}
}
- You must be logged in to reply to this topic.