Please make sure to update to WPML 4.3.5 and check our list of Known Issues before reporting

Hi, Amit here, I am the WPML Support Manager, our current ticket queue is high, update your WPML plugins and make sure you meet the minimal requirements for running WPML before reporting an issue please - many tickets are resolved doing that

Please look at our updated list of Known Issues and you can also use our support search to find helpful information and of course review our documentation before opening a ticket.

If you do need to open a ticket please make sure to provide us with all the needed information as described in this page

This is the technical support forum for WPML - the multilingual WordPress plugin.

Everyone can read, but only WPML clients can post here. WPML team is replying on the forum 6 days per week, 22 hours per day.

Tagged: 

This topic contains 1 reply, has 2 voices.

Last updated by Bruno 9 months, 1 week ago.

Assigned support staff: Bruno.

Author Posts
February 26, 2019 at 10:24 am #3244120

bomannN

I have woocommerce products in Language X.
I have a UI where admin can modify attributes of products and update.
In our project we have language X as the default language.

ajax for product update


    $fields = isset($_POST) ? $_POST: array();

    global $sitepress;
    $current_lang = $sitepress->get_current_language();
    $default_lang = $sitepress->get_default_language();
    $sitepress->switch_lang($default_lang);

    $my_current_lang = apply_filters( 'wpml_current_language', NULL ); 

    if( $fields['product-edit-id'] != '' ) {
        switch_to_blog(1);
        
            $edit_post = get_post( $fields['product-edit-id'] );
			
			$woo_product = wc_get_product($fields['product-edit-id']);
			$woo_type = $woo_product->get_type();
			
			if( $woo_type == 'variable' ) {
				$attributes = $woo_product->get_attributes();
				$variations = $woo_product->get_available_variations();
			}
            
            
        restore_current_blog();
    }
    

Our post update looks like this

$edit_product = get_page_by_path($edit_post->post_name, OBJECT, 'product');
                
				$product = array(
					'ID' => $edit_product->ID,
					'post_title' => $fields['product-name-input'],
					'post_excerpt' => $fields['product-description-input'],
					'post_status' => $status,
					'post_parent'  => '',
					'post_type' => 'product'
				);
				
				$post_id = wp_insert_post($product, true);

When the admin uses the language switcher(in header) and changes to Language Y and updates the product,
$my_current_lang returns the default language X, but if I add ICL_LANGUAGE_CODE for debug purposes it returns Y

Also for some reason we find that now the product in the back-end is changed to language Y and language X product does not exist anymore.
What could the issue be?

February 26, 2019 at 8:32 pm #3247264

Bruno
Supporter

Languages: English (English ) Portuguese (Brazil) (Português )

Timezone: America/Sao_Paulo (GMT-03:00)

Thank you for contacting us. To know exactly what is happening you may need a deeper debug. Overall, to use AJAX with WPML you should follow the steps below:

- Click on the WPML > Languages > Language filtering for AJAX operations
- Check the "Store a language cookie to support language filtering for AJAX" option
- Click on the Save button

If the problem still persists, you may need to pass the language code directly into the AJAX call, so you can retrieve it later.

>>> Also for some reason we find that now the product in the back-end is changed to language Y and language X product does not exist anymore.
What could the issue be?

This may be happening just because the language is not being passed correctly. After following the steps above, see if the problem still persists.

Please note that unfortunately, custom coding is beyond the scope of our support.

We have a list of WPML and WooCommerce Multilingual hooks that can help you develop such feature, which can be seen in the links below:

- https://wpml.org/documentation/support/wpml-coding-api/wpml-hooks-reference
- https://wpml.org/documentation/related-projects/woocommerce-multilingual/wcml-hooks-reference/

If you prefer, you can contact one of our certified partners who can develop small to large features for your site: http://wpml.org/documentation/support/wpml-contractors/

Please, let me know if I can help with any other questions you may have about it. I'll be happy to help.

Thank you.