Forum Replies Created

Viewing 15 replies - 46 through 60 (of 187 total)
  • Thread Starter devsaredead

    (@devsaredead)

    hello again. You can read the full code hereby:

    /* New Product Tab @ 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( '[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"]' );
    }
    }
    }

    This is the category where the code appears (just open a product and see the custom tab “Preventivo/Quotation”), whereas it should not appear in all other categories. Looking forward to your kind help πŸ™‚

    Thread Starter devsaredead

    (@devsaredead)

    Thank you for your time anyway. It looked like we were close to the solution πŸ™‚

    Thread Starter devsaredead

    (@devsaredead)

    hello, I’m catching up because you left me without a solution. Can you look at this again? thanks

    Thread Starter devsaredead

    (@devsaredead)

    πŸ™‚ that is the code that works showing the custom tab to every product. I could not understand where to include the changes you proposed in order to filter out all product_cat except noleggio/rents, I have made many attempts but either I modify it wrong or maybe it doesn’t work. Please be so kind to amend the code as it really should be, because I’m really lost, I’d appreciate a lot πŸ™‚

    Thread Starter devsaredead

    (@devsaredead)

    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"]' );
    }
    }
    }
    Thread Starter devsaredead

    (@devsaredead)

    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"]' );
    }


    Thread Starter devsaredead

    (@devsaredead)

    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"]' );
    }

    Thread Starter devsaredead

    (@devsaredead)

    I don’t get it. Where does it fetch the $tabs from?

    Thread Starter devsaredead

    (@devsaredead)

    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

    Thread Starter devsaredead

    (@devsaredead)

    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]' );
    }
    }
    }
    Thread Starter devsaredead

    (@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' ) ) and if ( has_term ( 'rents', 'product_cat' ) ) ?

    Thread Starter devsaredead

    (@devsaredead)

    they were not initially when I had A+, but once I enabled them the test downgraded

    Thread Starter devsaredead

    (@devsaredead)

    you mean the “duplicates”? yes they are.

    If I use a manual htaccess method I get A+, so the plugin is somehow less reliable than the manual option

    Thread Starter devsaredead

    (@devsaredead)

    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 year, 7 months ago by devsaredead.
    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 - 46 through 60 (of 187 total)