labels in the store randomly change to English

[ad_1]

What other plugins and theme do you use on the site?

The theme is Flatsome with many plugins. The problem occurs when the plugin is enabled. I disabled all plugins to determine which one is causing this issue.

I changed the code to this, and everything worked, but there will be a problem if someone wants to change the language in the future.

/** * Change the language codes of Contact Form 7 forms from English to German.

* * This function changes the language codes of Contact Form 7 forms

* from ‘en_US’ to ‘de_DE’. It checks if Contact Form 7 is active by

* verifying the existence of the WPCF7_ContactForm class. *

* @return void */

function change_cf7_forms_to_german() { $new_locale = ‘de_DE’; $old_locale = ‘en_US’;

// Ensure new locale is provided and check if Contact Form 7 is active. if ( ! class_exists( ‘WPCF7_ContactForm’ ) ) { return;

// Check if Contact Form 7 is active. }

// Query to get all Contact Form 7 posts. $args = array( ‘post_type’ => ‘wpcf7_contact_form’, ‘posts_per_page’ => -1,

// Get all forms. ); $cf7_forms = get_posts( $args );

// Loop through forms to filter and update locale. foreach ( $cf7_forms as $form ) { $form_id = $form->ID; $locale = get_post_meta( $form_id, ‘_locale’, true );

// If locale matches old locale, update to new locale. if ( $locale === $old_locale ) { update_post_meta( $form_id, ‘_locale’, $new_locale ); } } }

// Example usage change_cf7_forms_to_german();

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer