• Resolved Alex4842

    (@alex4842)


    Hello i would like please your help. I would like to check what lang is and depend on lang to load a specific CF7. Can you please help me? I am sorry but i am newbie and still trying to figure it out. I want to add this code on functions.php. I have this code:`

    if ( ! defined( ‘ABSPATH’ ) ) exit;
    /**
    * Check if WooCommerce is active
    **/
    if ( ! in_array( ‘woocommerce/woocommerce.php’, apply_filters( ‘active_plugins’, get_option( ‘active_plugins’ ) ) ) ) {
    return;
    }
    // let’s add a filter to woocommerce_product_tabs to add our additional tab..
    add_filter(‘woocommerce_single_product_summary’,’woocommerce_product_tabs_contact_form7′,10,1);
    function woocommerce_product_tabs_contact_form7($tabs){

    $tabs[‘contact_form7’] = array(
    ‘title’ => __( ‘Enquiry’, ‘woocommerce’ ),
    ‘priority’ => 20,
    ‘callback’ => ‘woocommerce_product_contact_form7_tab’
    );

    return $tabs;
    }
    // our tab’s callback…
    function woocommerce_product_contact_form7_tab(){
    // do the thing zhu li! Let’s echo our shortcode for contact form 7
    echo do_shortcode(‘[contact-form-7 id=”216″ title=”Product Form”]’);
    }`
    And i want if it is englsih to load the 216 contact form e.g. if it is greek to load for instance 217 form. Can you please help me?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Try this:

    function woocommerce_product_contact_form7_tab(){
    if (get_locale() == “en_US”) {
    echo do_shortcode(‘[contact-form-7 id=”216″ title=”Product Form”]’);
    }
    else {
    echo do_shortcode(‘[contact-form-7 id=”217″ title=”Product Form”]’);
    }
    }

    Thread Starter Alex4842

    (@alex4842)

    Thank you @bhawanvirk for your answer i tried it on functions.php but when i save it it doensn;t load the site.

    Did you replace the function “woocommerce_product_contact_form7_tab” with the one i provided or did you just added it at the bottom of your functions.php file? Btw what error are you getting? if page is just showing blank then turn on debugging by going to your wp-config.php file and find this piece of code define('WP_DEBUG', false); and then replace it with define('WP_DEBUG', true);

    Here’s your solution if your are trying to add an enquiry tab on your product page which shows a contact form based on your site language. It will show form with id 216 if your site language is set to english, otherwise form with id 217. Replace the code that you have listed above with this.

    
    // let’s add a filter to woocommerce_product_tabs to add our additional tab..
    add_filter('woocommerce_product_tabs','woocommerce_product_tabs_contact_form7',10,1);
    
    function woocommerce_product_tabs_contact_form7($tabs){
    	$tabs['contact_form7'] = array(
    	'title' => __( 'Enquiry', 'woocommerce' ),
    	'priority' => 20,
    	'callback' => 'woocommerce_product_contact_form7_tab'
    	);
    
    	return $tabs;
    }
    // our tab’s callback…
    function woocommerce_product_contact_form7_tab(){
    	if (get_locale() == "en_US") {
    		echo do_shortcode('[contact-form-7 id=”216″ title=”Product Form”]');
    	}
    	else {
    		echo do_shortcode('[contact-form-7 id=”217″ title=”Product Form”]');
    	}
    }
    
    Thread Starter Alex4842

    (@alex4842)

    Thank you so much @bhawanvirk for the answer!!! yes you had right my fault i didn’t replace it.. ?? one more question can you help me if you know how can i get the title of the product that i am into page on the email of the contact form 7(e.g. if i am on milk and someone ask about the milk, in the email to write that is for milk)? Again many thanks for your time and help!! ??

    Thread Starter Alex4842

    (@alex4842)

    Found it!!! i added on contact form 7->mail->subject [_post_title]. Once more many thanks for your time and help!!! ??

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘how can i control which lang do i have’ is closed to new replies.