• Resolved Alex4842

    (@alex4842)


    Hello and thank you for this amazing plugin! I am having a little bit a problem. I have a multilingual site (english and greek),and it doesn’t show the correct form on each language.I have downloaded Polylang and CF7 and i installed your module as the installation is described. I created an english and there was an option to create the specific in greek so i did ( it was translated partially ) but still when i go on the greek it loads only the english.I followed your instructions on FAQ but nothing changed. Can you please help me?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter Alex4842

    (@alex4842)

    i might detected the problem 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"]');
    }

    in the functions.php to show the contact form on each product. Is there a way i can alter the code to control depend on the language to show the specific code?

    Plugin Author Aurovrata Venet

    (@aurovrata)

    Indeed, your function is always calling the same CF7 (id=216), when in fact it should call the translated form depending on which language is being queried. Use the Polylang function, pll_get_post() to obtain the translated post,

    // our tab's callback...
    function woocommerce_product_contact_form7_tab(){
      $cf7_id = pll_get_post('216');
      $cf7_form = wpcf7_contact_form($cf7_id); //cf7 plugin function to load the correct form
      if(!empty($cf7_form) ){
        $scode = $cf7_form.shortcode();
        echo do_shortcode($scode);
      }else{
        echo 'No translated form found for CF7 Form id:'.$cf7_id;
      }
    }
    
    Thread Starter Alex4842

    (@alex4842)

    Thank you @aurovrata so much for the answer!! I used it but it still loads on both english and greek the english form.

    Plugin Author Aurovrata Venet

    (@aurovrata)

    can you echo the code results to make sure it is working properly, especially the $cf7_id.

    Can you also create a page and put the english form shortcode in and the greek form shortcode in the translated page to test that the forms work.

    Plugin Author Aurovrata Venet

    (@aurovrata)

    Have you resolved this issue?

    Please note that this plugin only manages translations of your forms in the dashboard. It does affect the way your display these forms in the front end.

    You need to make sure you use the right form on the right page in teh front end. If you wish to build your forms dynamically into your pages according to the language that is loaded you must use the following code,

    
    //use the polyang function pll_get_post($post_id) to get the translation in the current language
    $cf7_id = pll_get_post('216'); //216 is the form id in the default language
    //you should check that a translation exists
    $cf7_form = wpcf7_contact_form($cf7_id); //cf7 plugin function to load the form
    $scode = $cf7_form.shortcode();
    echo do_shortcode($scode);
    

    your problem arises because the WooCommerce plugin is loading the same form regardless of the current language. You need to make sure you understand how WooCommerce displays the form and hook your functionality properly.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘still doesn’t show the correct form’ is closed to new replies.