Title: error in wp
Last modified: May 22, 2025

---

# error in wp

 *  [glowzar](https://wordpress.org/support/users/glowzar/)
 * (@glowzar)
 * [1 year ago](https://wordpress.org/support/topic/error-in-wp-2/)
 * **please fix the bug. I have made a patch myself.**
 * **Impact**: swatches won’t load well , the error leaks in json responses.
 * The error “Translation loading for the wcvs domain was triggered too early” occurs
   because translations are being used before the text domain is properly loaded.
   Here’s how to fix it:
    1. In class-variation-swatches.php:
 *  - Move the translations out of the constructor
    - Initialize types with untranslated strings first
    - Add translations after init hook
 *  1. In variation-swatches-for-woocommerce.php:
 *  - Remove early text domain loading from plugins_loaded
    - Add proper text domain loading on init hook
 * Here’s the specific code changes needed:
    1. In class-variation-swatches.php:
 *     ```wp-block-code
       public function __construct() {
           // Initialize with untranslated strings
           $this->types = array(
               'color' => 'Color',
               'image' => 'Image',
               'label' => 'Label',
           );
   
           if ( TA_WC_Variation_Swatches::is_pro_addon_active() ) {
               $this->types['radio'] = 'Radio button';
           }
   
           $this->includes();
           $this->init_hooks();
       }
   
       public function init_hooks() {
           // Add translations after init
           add_action( 'init', array( $this, 'load_translations' ) );
           // ... rest of your hooks
       }
   
       public function load_translations() {
           // Apply translations after text domain is loaded
           $this->types = array(
               'color' => esc_html__( 'Color', 'wcvs' ),
               'image' => esc_html__( 'Image', 'wcvs' ),
               'label' => esc_html__( 'Label', 'wcvs' ),
           );
   
           if ( TA_WC_Variation_Swatches::is_pro_addon_active() ) {
               $this->types['radio'] = esc_html__( 'Radio button', 'wcvs' );
           }
       }
       ```
   
    2. In variation-swatches-for-woocommerce.php:
 *     ```wp-block-code
       // Remove text domain loading from constructor
       function ta_wc_variation_swatches_constructor() {
           if ( ! function_exists( 'WC' ) ) {
               add_action( 'admin_notices', 'ta_wc_variation_swatches_wc_notice' );
           } elseif ( defined( 'TAWC_VS_PRO' ) ) {
               add_action( 'admin_notices', 'ta_wc_variation_swatches_pro_notice' );
               deactivate_plugins( plugin_basename( __FILE__ ) );
           } else {
               require_once plugin_dir_path( __FILE__ ) . '/includes/class-variation-swatches.php';
               TA_WCVS();
           }
       }
   
       // Add proper text domain loading
       function ta_wc_variation_swatches_load_textdomain() {
           load_plugin_textdomain( 'wcvs', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
       }
       add_action( 'init', 'ta_wc_variation_swatches_load_textdomain' );
       ```
   
 * This fix ensures that:
    1. The text domain is loaded at the proper time (during init)
    2. No translations are attempted before the text domain is loaded
    3. The plugin’s functionality remains intact
 * The error occurs because WordPress 6.7.0 added stricter checks for text domain
   loading timing. Translations should only be loaded at the init action or later,
   which this fix properly implements.
    -  This topic was modified 1 year ago by [glowzar](https://wordpress.org/support/users/glowzar/).
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Ferror-in-wp-2%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

The topic ‘error in wp’ is closed to new replies.

 * ![](https://ps.w.org/variation-swatches-for-woocommerce/assets/icon-256x256.png?
   rev=2602534)
 * [Variation Swatches for WooCommerce](https://wordpress.org/plugins/variation-swatches-for-woocommerce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/variation-swatches-for-woocommerce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/variation-swatches-for-woocommerce/)
 * [Active Topics](https://wordpress.org/support/plugin/variation-swatches-for-woocommerce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/variation-swatches-for-woocommerce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/variation-swatches-for-woocommerce/reviews/)

 * 0 replies
 * 1 participant
 * Last reply from: [glowzar](https://wordpress.org/support/users/glowzar/)
 * Last activity: [1 year ago](https://wordpress.org/support/topic/error-in-wp-2/)
 * Status: not resolved